search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

1 answers
Q&A django中static文件的处理
django中static文件的处理
高洛峰 2016-11-14 10:08:32 Views 1503

0

先帖代码跟项目结构项目结构

├── gameOps
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── dufgame
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── models.py
│   ├── signals.py
│   ├── templates
│   │   └── dufindex.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── run.py
├── static
│   ├── css
│   │   ├── base.css
│   │   ├── bootstrap.css
│   │   ├── bootstrap.css.map
│   │   ├── bootstrap.min.css
│   │   ├── bootstrap-theme.css
│   │   ├── bootstrap-theme.css.map
│   │   └── bootstrap-theme.min.css
│   ├── fonts
│   │   ├── glyphicons-halflings-regular.eot
│   │   ├── glyphicons-halflings-regular.svg
│   │   ├── glyphicons-halflings-regular.ttf
│   │   └── glyphicons-halflings-regular.woff
│   └── js
│       ├── bootstrap.js
│       ├── bootstrap.min.js
│       ├── jquery.js
│       ├── jquery.min.js
│       └── npm.js
└── templates
    ├── base.html
    ├── leftpage.html
    └── tmp.html

templates/base.html 为基础模板
访问:http://192.168.50.137:8000/呈现的是base.html内容
dufgame/templates/dufindex.html中的内容部分继承了templates/base.html中的内容
访问:http://192.168.50.137:8000/duf/呈现的是dufgame/templates/dufindex.html中的内容

gameOps/setting.py中关于静态文件的设置

STATIC_URL = '/static/'
STATICFILES_DIRS  = (os.path.join(BASE_DIR,'static'),)

templates/base.html中的静态文件内容




Game Ops

{% load staticfiles %}


访问:http://192.168.50.137:8000/duf/打印的日志信息

INFO "GET /duf/ HTTP/1.1" 200 8634
INFO "GET /static/css/base.css HTTP/1.1" 304 0
WARNING "GET /duf/static/js/jquery.min.js HTTP/1.1" 404 2789
WARNING "GET /duf/static/js/bootstrap.min.js HTTP/1.1" 404 2798
WARNING "GET /duf/static/js/jquery.min.js HTTP/1.1" 404 2789
WARNING "GET /duf/static/js/bootstrap.min.js HTTP/1.1" 404 2798

问题来了,我的静态文件要怎么设置才能在访问http://192.168.50.137:8000/duf/时候也能调用到。

Your Answer
submit

1 answers
0

可以参考这个来定义static文件https://segmentfault.com/a/1190000007132294


2016-11-14 10:08:57

submit

Popular tool

vc9-vc14 (32+64 bit) runtime library collection (link below)

vc9-vc14 (32+64 bit) runtime library collection (link below)

Download the collection of runtime libraries required for phpStudy installation

VC9 32-bit

VC9 32-bit

VC9 32-bit phpstudy integrated installation environment runtime library

PHP programmer toolbox full version

PHP programmer toolbox full version

Programmer Toolbox v1.0 PHP Integrated Environment

VC11 32-bit

VC11 32-bit

VC11 32-bit phpstudy integrated installation environment runtime library

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use