标签:manage 路径 域名 pre cti dir pip 中间件 event
1.跨域问题
pip install django-cors-headers 模块
setting配置apps和中间件、
跨域
2.静态文件迁移和显示配置
dubug = False
配置url
from django.conf import setting
# url里添加 re_path(r‘^static/(?P<path>.*)$‘, serve, {‘document_root‘: settings.STATIC_ROOT}, name=‘static‘)
settings配置static
STATIC_URL = ‘/static/‘ STATIC_ROOT = os.path.join(BASE_DIR, ‘static‘) STATICFILES_DIRS = ( os.path.join(BASE_DIR, ‘/static/‘), )
静态文件迁移
# 1.创建文件夹 static,和setting配置路径对应 # 2.使用命令 python manage.py collectstatic # 迁移成功 # 可能报错原因,static文件夹路由不正确
用nginx部署配置静态
events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; server { listen 8000; server_name 127.0.0.1; # 改为自己的域名,没域名修改为127.0.0.1:80 charset utf-8; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8808; # 端口要和uwsgi里配置的一样 uwsgi_param UWSGI_SCRIPT api.wsgi; #wsgi.py所在的目录名+.wsgi uwsgi_param UWSGI_CHDIR /home/project/api/; # 项目路径 } # 新增的配置静态文件 location /static { alias /home/project/luffyapi/luffyapi/static; } } }
标签:manage 路径 域名 pre cti dir pip 中间件 event
原文地址:https://www.cnblogs.com/xiaowangba9494/p/14207448.html