当前位置: 首页 > news >正文

django静态文件无法访问解决方案

nginx配置如下:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;
}http {log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile            on;tcp_nopush          on;tcp_nodelay         on;keepalive_timeout   65;types_hash_max_size 4096;include             /etc/nginx/mime.types;default_type        application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;server {listen       8000; #设置的nginx访问端口server_name  test;charset      utf-8;location /static {autoindex on;alias /home/mysite/static; #具体目录以您现场具体部署的目录为准}}
# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }}

写两套模板,一套用于开发,一套用于部署,视图中判断返回哪套

    if settings.DEBUG:return render(request, "example.html", locals())else:return render(request, "example.html", locals())
http://www.lryc.cn/news/147684.html

相关文章:

  • WIndows 配置多版本python环境,非常清晰明了
  • Leetcode每日一题:1267. 统计参与通信的服务器(2023.8.24 C++)
  • c++(8.28)菱形继承,虚继承,多态,抽象类,模板+Xmind
  • 安装部署JavaFX和IDEA添加JavaFX的详细步骤
  • MAC电脑外放没有声音解决方案
  • Spring源码分析(八)CreateBean与DoCreateBean
  • iSCSI存储服务器
  • 信息技术02--初/高中--分类选择题(377道题与解析)
  • java --- 枚举类
  • nvm和volta对node版本控制的区别
  • 高斯消元解线性方程组
  • 【linux命令讲解大全】032.介绍 Linux 中的 rcp 命令:简化主机间文件复制操作
  • Mysql索引、事务与存储引擎 (事务、MySQL 存储引擎)
  • Doris(六)--通过 Canal 同步数据到 Doris 中
  • 快手Java一面,全是基础
  • 未来芯片设计领域的药明康德——青芯如何在N个项目间游走平衡
  • 【跟小嘉学 Rust 编程】十九、高级特性
  • pandas由入门到精通-数据清洗-缺失值处理
  • Redis 教程 - 主从复制
  • [递归] 子集 全排列和组合问题
  • ELK安装、部署、调试(四)KAFKA消息队列的安装和部署
  • 半导体晶片机器视觉测量及MARK点视觉定位
  • ranger无法同步用户问题解决
  • 使用通信顺序进程(CSP)模型的 Go 语言通道
  • VPN网关
  • 产品展示视频制作的要点
  • appium+python自动化测试
  • 【AI辅助办公】PDF转PPT,移除水印
  • ssm农业视频实时发布管理系统源码
  • 【100天精通python】Day48:python Web开发_WSGI接口与使用