gpt4 book ai didi

django - nginx-django 2- Angular 6/重路由页面后 Angular 路由获取404

转载 作者:行者123 更新时间:2023-12-02 00:59:47 25 4
gpt4 key购买 nike

其django和angular 6(使用静态文件)项目。当我刷新浏览器时,我得到404 not found错误..我进行的搜索很少,并且根据此answer,这次我在刷新工作中执行了角路由相同的操作(不获得404),但是我收到服务器错误,提示以下错误*请参阅我的上载图片 :

*角度静态文件位于静态文件夹中

 "Http failure during parsing for http://robinlearn.com/api/v1/store/view-global-discount/"

name: "HttpErrorResponse"

full error

url.py:
   urlpatterns = [
url(r'^(?!ng/).*$', HomePageView.as_view(),name="angular_app")

]
urlpatterns += static(base.STATIC_URL, document_root=base.STATIC_ROOT) + \
static(base.MEDIA_URL, document_root=base.MEDIA_ROOT)

urlpatterns += static(base.ANGULAR_URL, document_root=base.STATIC_ROOT)

View :
 class HomePageView(TemplateView):
def get(self, request, **kwargs):
return render(request, 'index.html', context=None)

Nginx的配置:
    listen 80;
server_name robinlearn.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/bio/academy;
}

location / {

include proxy_params;
#proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/home/bio/academy/academy.sock;
}
}

设置:
PROJECT_ROOT = os.path.dirname(os.path.dirname((__file__)))
#STATIC_ROOT = BASE_DIR+'/academy/staticfiles'
STATIC_URL = '/static/'

STATIC_ROOT = os.path.join((BASE_DIR),"static")
#MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR),"media")

SS_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)

这是我的index.html(在模板文件夹中),它加载静态角度
{% load static %}
<!DOCTYPE html>
<html lang="fa" id="persain">
<head>
<meta charset="utf-8">
<title>robin</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="{% static 'favicon.png' %}">
<link rel="stylesheet" href="{% static 'styles.9be16346d4b858749d38.css' %}"></head>
<body>
<app-root>Loading . . .</app-root>
<script type="text/javascript" src="{% static 'runtime.6afe30102d8fe7337431.js' %}"></script>
<script type="text/javascript" src="{% static 'polyfills.b0205464c9bd4e7fe3b3.js' %}"></script>
<script type="text/javascript" src="{% static 'scripts.59ed76cc23ba77b0ec72.js' %}"></script>
<script type="text/javascript" src="{% static 'main.bfc87555f7931caf0a5b.js' %}"></script>
</body>
</html>

最佳答案

将url(r'^(?! ng /).*$',HomePageView.as_view(),name =“angular_app”)行移到最底端而不是像现在一样移至顶层,以便Django给出假设这些行之一是您的API,API URL的优先级

关于django - nginx-django 2- Angular 6/重路由页面后 Angular 路由获取404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51477058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com