python : 3.6.4css
django : 2.0html
1 文件目錄 /var/www/mysitepython
2 nginx配置:nginx
server { listen 8000; #暴露給外部訪問的端口 server_name localhost; charset utf-8; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8997; #外部訪問8000就轉發到內部8997 } location /static { alias /var/www/mysite/static; } }
3 setting.py 配置django
STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), os.path.join(BASE_DIR, "recommend", "static"), ]
4 html 配置spa
{% load static %} <!DOCTYPE html> <html> <head> <title>test</title> <link rel="stylesheet" href="{% static '/css/index.css' %}">
5 重啓uwsgi debug
cd /var/www/mysite killall -9 uwsgi uwsgi -x mysite.xml
注意一點:code
debug 開啓時。 django 會幫你加載靜態文件server
debug 關閉以後, django 就沒法幫你加載靜態文件了,你要用 nignx 配置xml