
网址:py:
urlpatterns=[
URL(R’^(?)!ng/).*$”,homepageview.as_View(),name=“angular_app”)
]
urlpatterns+=静态(base.static_url,document_root=base.static_root)+\
静态(base.media_url,document_root=base.media_root)
urlpatterns+=静态(base.angular_url,document_root=base.static_root)
视图:
class homepageview(模板视图):
def get(self,请求,**kwargs):
返回呈现(请求,'index.html',context=none)
nginx配置:
listen 80;
服务器名称robinlearn.com;
location=/favicon.ico访问注销;未找到注销;
位置/静态/{
根/家/生物/学院;
}
位置/{
包括代理参数;
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$方案;
代理通行证http://unix:/home/bio/academy/academy.sock;
}
}
设置:
project_root=os.path.dirname(os.path.dirname((uu file_uuu)))
静态“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(uuu file_uuuuu)))
#用于CollectStatic查找静态文件的额外位置。
静态文件目录=(
os.path.join(project_root,'static'),
)
这是我的index.html(在template文件夹中)加载静态角度
%load static%
&!文档类型HTML>
<html lang=“fa”id=“persain”>
<头部>
<meta charset=“utf-8”>
<title>罗宾</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>
<正文>
<app root>正在加载。..</app根目录
<script type=“text/javascript”src=“%static”运行时.6afe30102d8fe7337431.js“%”></script>
<script type=“text/javascript”src=“%static”polyfills.b0205464c9b4e7fe3b3.js“%”></script>
<script type=“text/javascript”src=“%static”scripts.59ed76cc23ba77b0ec72.js“%”></script>
<script type=“text/javascript”src=“%static”main.bfc87555f7931caf0a5b.js“%”></script>
</body>
</html>
answer我这次在刷新工作中做了同样的事情(不要得到404),但是我得到了服务器错误,上面写着以下错误*请查看我上传的图片:
*角度静态文件位于静态文件夹中
"Http failure during parsing for http://robinlearn.com/api/v1/store/view-global-discount/"
â
name: "HttpErrorResponse"

网址.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)
观点:
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 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_URL = '/static/'
STATIC_ROOT = os.path.join((BASE_DIR),"static")
SS_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
这是我的index.html(在template文件夹中)加载静态角度
{% 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>