django 加载css 、js 、img 等静态文件(第二节) 教程

python : 3.6.4

django : 2.0

nginx:1.12

 

1、文件目录  /var/www/mysite文件目录  /var/www/mysite

 

2 、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 配置

STATIC_URL = '/static/'

STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, "static"), 
    os.path.join(BASE_DIR, "recommend", "static"), 
] 

 

4、html 配置

{% load static %}
<!DOCTYPE html>
<html>
<head>
    <title>test</title>
    <link rel="stylesheet" href="{% static '/css/index.css' %}">

 

5 、重启uwsgi

cd /var/www/mysite
killall -9 uwsgi
uwsgi -x mysite.xml
头像
  • ¥ 299.0元
  • 市场价:599.0元
  • ¥ 199.0元
  • 市场价:199.0元
  • ¥ 99.9元
  • 市场价:299元
  • ¥ 59.8元
  • 市场价:99.8元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: