惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - hgdfr

Django1.5内置的用户认证系统介绍(之五)在admin后台管理用户 --by hillfree Django1.5内置的用户认证系统介绍(之四)Authentication in Web requests --by hillfree Django1.5内置的用户认证系统介绍(之三)权限与授权--by hillfree Django1.5内置的用户认证系统介绍(之二)使用User对象--by hillfree Django1.5内置的用户认证系统介绍(之一)--by hillfree Django REST Framework Tutorial 5:关系与超链接API(中文版教程)by hillfree Django REST Framework Tutorial 4:认证与权限(中文版教程)by hillfree Django REST Framework Tutorial 3:基于类的Views(中文版教程)by hillfree Django1.5+Python3.3下groundwork的使用 参照《鲜活的数据:数据可视化指南》第2章:抓取网页数据(历史天气记录)的Python程序 - hgdfr Python3.3中如何产生伪随机数 《鲜活的数据:数据可视化指南》第2章 收集数据 Python3.3源码 CSCW领域的“老”词和“新”词 FOAF简介和朋友圈子 Class Library类型的工程难道不能用app.config? 配置文件中的DataDirectory在那里设置? 自己写的类需要重写ToString(), HashCode(), Equal()吗? 注释中如果出现尖括号怎么办?“<” - hgdfr - 博客园 Access Control Issues 有关访问控制
Django1.5中设置静态目录的简要说明
hgdfr · 2013-03-21 · via 博客园 - hgdfr

网上查到不少关于设置静态目录的,版本有些差异,对新手而言,在Django1.5上总有这样那样的问题。例如一开始遇到的Settings不存在之类的(此时需要增加from django.conf import settings)。从相关文章中(具体链接见下)摘取整理相关内容,作为自己的新手笔记留存:

(一)开发阶段(DEBUG = True)

  • 1. 打开项目的settings.py配置文件,作如下改动:
    • import os  # 增加引入
    • CURRENT_DIR = os.path.dirname(__file__).replace('\\','/') #增加当前目录变量 
    • STATIC_ROOT = '' #暂不改动
    • STATIC_URL = '/static/'  # 或其他也可
    • STATICFILES_DIRS = (
          CURRENT_DIR +STATIC_URL,)  #增加一项
  • 2. 打开项目的urls.py问价,作如下改动:
    • from django.contrib.staticfiles.urls import staticfiles_urlpatterns  # 增加引入
    • urlpatterns += staticfiles_urlpatterns() # 增加一行urlpatterns
  • 3. 在templates里使用静态文件了:

    <script type="javascript/text" src="/static/js/config.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/css/contents.css"/>
    <img src="/static/images/logo.ipg" alt=""/>

    使用的时候注意 路径的开头需要加上“/” 

(二)部署阶段(DEBUG = False)

在django1.5的doc里面有介绍如下(自己还没有试):

When you’re ready to move out of local development and deploy your project:

  1. Set the STATIC_URL setting to the public URL for your static files (in most cases, the default value of/static/ is just fine).

  2. Set the STATIC_ROOT setting to point to the filesystem path you’d like your static files collected to when you use the collectstatic management command. For example:

    STATIC_ROOT = "/home/jacob/projects/mysite.com/sitestatic"
  3. Run the collectstatic management command:

    ./manage.py collectstatic
    

    This’ll churn through your static file storage and copy them into the directory given by STATIC_ROOT.

  4. Deploy those files by configuring your webserver of choice to serve the files in STATIC_ROOT atSTATIC_URL.

    Serving static files in production covers some common deployment strategies for static files.

Those are the basics. For more details on common configuration options, read on; for a detailed reference of the settings, commands, and other bits included with the framework see the staticfiles reference.

posted @ 2013-03-21 14:36  hgdfr  阅读(656)  评论()    收藏  举报