Your Django settings file contains all the configuration of your Django installation. This appendix explains how settings work and which settings are available.
浣犵殑 Django 璁剧疆鏂囦欢鍖呭惈浜嗘墍鏈夌殑 Django 瀹夎閰嶇疆銆傛湰闄勫綍瑙i噴浜嗗浣曡缃幓浣垮畠宸ヤ綔浠ュ強鍝簺璁剧疆鏄湁鏁堢殑銆
Note
娉ㄦ剰
As Django grows, its occasionally necessary to add or (rarely) change settings. You should always check the online settings documentation at http://www.djangoproject.com/documentation/0.96/settings/ for the latest information.
闅忕潃Django鐨勫彂灞曪紝瀹冩湁鏃跺欓渶瑕佹坊鍔犳垨鏀瑰彉锛堝緢灏戯級涓浜泂ettings 锛屼綘搴旇缁忓父鍘绘煡鐪嬪湪绾跨殑settings 鏂囨。锛 http://www.djangoproject.com/documentation/0.96/settings/ 锛夛紝浜嗚В鏈鏂扮殑淇℃伅銆
A settings file is just a Python module with module-level variables.
涓涓 settings 鏂囦欢 鍙槸涓涓湁涓浜涙ā鍧楃骇鍙橀噺鐨凱ython妯″潡銆
Here are a couple of example settings:
杩欓噷鏄竴浜泂ettings渚嬪瓙锛
DEBUG = False DEFAULT_FROM_EMAIL = 'webmaster@example.com' TEMPLATE_DIRS = ('/home/templates/mike', '/home/templates/john')
Because a settings file is a Python module, the following apply:
鍥犱负涓涓猻ettings 鏂囦欢鏄竴涓猵ython妯″潡锛屽繀椤荤鍚堜笅闈㈢殑涓浜涚殑瑙勫垯锛
It must be valid Python code; syntax errors arent allowed.
瀹冨繀椤绘槸鍚堟硶鐨刾ython浠g爜锛屼笉鍏佽璇硶閿欒銆
It can assign settings dynamically using normal Python syntax, for example:
鍙互閫氳繃姝e父鐨刾ython璇硶缁檚ettings鍔ㄦ佽祴鍊硷紝姣斿锛
MY_SETTING = [str(i) for i in range(30)]
It can import values from other settings files.
瀹冨彲浠ヤ粠鍏朵粬settings 鏂囦欢瀵煎叆鍊笺
A Django settings file doesnt have to define any settings if it doesnt need to. Each setting has a sensible default value. These defaults live in the file django/conf/global_settings.py .
涓涓猟jango Settings鍙互涓虹┖,濡傛灉浣犱笉闇瑕佺殑璇濄傛瘡涓涓猄ettings鏈変竴涓垏鍚堝疄闄呯殑榛樿鍊硷紝杩欎簺榛樿鍊煎煎湪鏂囦欢 django/conf/global_settings.py 閲屻
Heres the algorithm Django uses in compiling settings:
涓嬮潰鏄痙jango鍦ㄧ紪璇憇ettings鏂囦欢鏃惰繍鐢ㄧ殑瑙勫垯锛
Load settings from global_settings.py .
浠 global_settings.py 瑁呰浇settings .
Load settings from the specified settings file, overriding the global settings as necessary.
浠庢寚瀹歴ettings 鏂囦欢瑁呰浇settings , 鍦ㄩ渶瑕佺殑鏃跺欙紝瑕嗙洊鍏ㄥ眬鐨剆ettings
Note that a settings file should not import from global_settings , because thats redundant.
娉ㄦ剰涓涓猻ettings 鏂囦欢涓嶅簲璇ュ鍏 global_settings 锛屽洜涓洪偅鏄浣欙紙鍐椾綑锛夌殑銆
Theres an easy way to view which of your settings deviate from the default settings. The command manage.py diffsettings displays differences between the current settings file and Djangos default settings.
鏈変竴涓鏄撶殑鏂规硶鏉ユ煡鐪嬩綘鐨勫摢浜汼ettings 鍜岄粯璁ょ殑Settings 涓嶅悓锛屽懡浠よ manage.py diffsettings 鍙互鏄剧ず褰撳墠鐨剆ettings 鏂囦欢鏂囦欢鍜岄粯璁ょ殑settings 鐨勪笉鍚屼箣澶勩
manage.py is described in more detail in Appendix G.
manage.py 鐨勬洿璇︾粏鎻忚堪鍦ㄩ檮褰旼锛
In your Django applications, use settings by importing the object django.conf.settings , for example:
鍦ㄤ綘鐨凞jango搴旂敤绋嬪簭涓,浠庡璞 django.conf.settings 瀵煎叆settings浣跨敤锛屼緥濡:
from django.conf import settings if settings.DEBUG: # Do something
Note that django.conf.settings isnt a module its an object. So importing individual settings is not possible:
娉ㄦ剰 django.conf.settings 涓嶆槸涓涓ā鍧楋紝鑰屾槸涓涓璞°傛墍浠ヤ笉鑳藉崟鐙鍏ettings锛
from django.conf.settings import DEBUG # This won't work.
Also note that your code should not import from either global_settings or your own settings file. django.conf.settings abstracts the concepts of default settings and site-specific settings; it presents a single interface. It also decouples the code that uses settings from the location of your settings.
鍚屾牱瑕佹敞鎰忥紝浣犵殑浠g爜涓 涓 搴旇瀵煎叆 global_settings 鎴栬呰嚜宸辩殑settings鏂囦欢銆 django.conf.settings 鎶借薄浜嗛粯璁ょ殑璁剧疆鍜屾瘡涓珯鐐圭殑璁剧疆锛涘畠鎻愪緵浜嗕竴涓崟涓鐨勬帴鍙c傚苟涓旓紝瀹冧篃浣垮緱浣犳墍鍐欑殑浠g爜涓庝綘鐨勮缃枃浠剁殑浣嶇疆娌℃湁鑰﹀悎銆
You shouldnt alter settings in your applications at runtime. For example, dont do this in a view:
浣犱笉搴旇鍦ㄤ綘鐨勫簲鐢ㄧ▼搴忚繍琛屾湡闂翠慨鏀硅缃, 渚嬪, 涓嶈鍦╲iew閲岄潰鍋氳繖鏍风殑浜嬫儏:
from django.conf import settings settings.DEBUG = True # Don't do this!
The only place you should assign to settings is in a settings file.
settings鏂囦欢搴旇鏄敮涓涓慨鏀 settings 鐨勫湴鏂.
瀹夊叏
Because a settings file contains sensitive information, such as the database password, you should make every attempt to limit access to it. For example, change its file permissions so that only you and your Web servers user can read it. This is especially important in a shared-hosting environment.
鍥犱负settings鏂囦欢鍖呭惈鏁忔劅淇℃伅,渚嬪鏁版嵁搴撳瘑鐮,浣犲簲璇ュ皾璇曢檺鍒惰闂畠.渚嬪,鏀瑰彉瀹冪殑鏂囦欢鏉冮檺浣垮緱鍙湁浣犲拰浣犵殑Web鏈嶅姟鍣ㄧ敤鎴峰笎鍙锋墠鑳借鍙栧畠.杩欏湪鍏变韩涓绘満鐜涓挨鍏堕噸瑕.
鍒涘缓浣犺嚜宸茬殑Settings
Theres nothing stopping you from creating your own settings, for your own Django applications. Just follow these conventions:
娌℃湁浠涔堣兘澶熼樆姝綘涓鸿嚜宸卞垱寤虹殑Django搴旂敤鍒涘缓settings銆 鍙閬靛畧浠ヤ笅绾﹀畾锛
Use all uppercase for setting names.
涓烘墍鏈夌殑閰嶇疆鍚嶄娇鐢ㄥぇ鍐欏瓧姣嶃
For settings that are sequences, use tuples instead of lists. Settings should be considered immutable and shouldnt be changed once theyre defined. Using tuples mirrors these semantics.
瀵逛簬闆嗗悎鍨嬬殑璁剧疆锛屼娇鐢ㄥ厓缁勶紙tuple锛夛紝鑰屼笉瑕佷娇鐢ㄥ垪琛紙list锛夈傛墍鏈夌殑璁剧疆搴旇鏄簰鏂ョ殑锛屽苟涓斾竴鏃︾‘瀹氫互鍚庡氨涓嶅簲璇ュ啀鏀瑰彉銆備娇鐢ㄥ厓缁勪篃鍙嶆槧浜嗚繖鏍风殑鐞嗗康銆
Dont reinvent an already existing setting.
涓嶈閲嶆柊鍒涘缓宸茬粡瀛樺湪鐨剆etting銆
When you use Django, you have to tell it which settings youre using. Do this by using the environment variable DJANGO_SETTINGS_MODULE .
褰撲綘浣跨敤 Django 鐨勬椂鍊欙紝浣犲繀椤诲憡璇夊畠浣犵敤鐨勫摢涓 settings 锛堥厤缃級锛屼綘鍙互閫氳繃璁剧疆 DJANGO_SETTINGS_MODULE 鐜鍙橀噺鏉ュ畬鎴愩
The value of DJANGO_SETTINGS_MODULE should be in Python path syntax (e.g., mysite.settings ). Note that the settings module should be on the Python import search path (PYTHONPATH ).
DJANGO_SETTINGS_MODULE 鐨勫煎簲璇ュ湪 Python path 涓紙渚嬪锛 mysite.settings 锛夈傛敞鎰忥紝settings 妯″潡搴旇鍦≒ython import鐨勬悳绱㈣矾寰勶紙 PYTHONPATH 锛変箣涓
Tip:
鎻愮ず锛
A good guide to PYTHONPATH can be found at http://diveintopython.org/getting_to_know_python/everything_is_an_object.html.
鍏充簬 PYTHONPATH 鐨勬寚瀵兼枃妗e彲浠ュ湪 http://diveintopython.org/getting_to_know_python/everything_is_an_object.html 鎵惧埌銆
When using django-admin.py (see Appendix G), you can either set the environment variable once or explicitly pass in the settings module each time you run the utility.
褰撲娇鐢 django-admin.py 锛堣闄勫綍G锛夋椂锛屼綘鍙互涓娆℃ц缃幆澧冨彉閲忔垨鑰呭湪姣忔杩愯杩欎釜宸ュ叿鏃朵簬settings妯″潡涓槑纭寚鏄庛
Heres an example using the Unix Bash shell:
杩欐槸涓涓娇鐢║nix Bash Shell鐨勪緥瀛愶細
export DJANGO_SETTINGS_MODULE=mysite.settings django-admin.py runserver
Heres an example using the Windows shell:
杩欐槸涓涓娇鐢╓indows鍛戒护琛岀殑渚嬪瓙锛
set DJANGO_SETTINGS_MODULE=mysite.settings django-admin.py runserver
Use the --settings command-line argument to specify the settings manually:
浣跨敤 --settings 鍛戒护琛屽弬鏁版潵鎵嬪伐鎸囨槑settings锛
django-admin.py runserver --settings=mysite.settings
The manage.py utility created by startproject as part of the project skeleton sets DJANGO_SETTINGS_MODULE` automatically; see Appendix G for more about manage.py .
鐢 startproject 鍒涘缓鐨勪綔涓哄伐绋嬮鏋朵竴閮ㄥ垎鐨 manage.py 宸ュ叿浼氳嚜鍔ㄨ缃 DJANGO_SETTINGS_MODULE` 锛涘叧浜 manage.py 鐨勮缁嗚鏄庤闄勫綍G銆
In your live server environment, youll need to tell Apache/mod_python which settings file to use. Do that with SetEnv :
鍦ㄤ綘鐨勫疄闄呮湇鍔″櫒鐜涓紝浣犻渶瑕佸憡璇堿pache/mod_python浣跨敤鍝竴涓猻ettings鏂囦欢銆傞氳繃 SetEnv 锛
<Location "/mysite/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings </Location>
For more information, read the Django mod_python documentation online at http://www.djangoproject.com/documentation/0.96/modpython/.
瑕佷簡瑙f洿璇︾粏鐨勪俊鎭紝璇烽槄璇籇jango mod_python鍦ㄧ嚎鎵嬪唽 http://www.djangoproject.com/documentation/0.96/modpython/ 銆
In some cases, you might want to bypass the DJANGO_SETTINGS_MODULE environment variable. For example, if youre using the template system by itself, you likely dont want to have to set up an environment variable pointing to a settings module.
鏈変簺鎯呭喌涓嬶紝浣犲彲鑳芥兂缁曡繃 DJANGO_SETTINGS_MODULE 鐜鍙橀噺銆備緥濡傦紝濡傛灉浣犳鍦ㄤ娇鐢ㄧ嫭绔嬬殑妯℃澘绯荤粺锛屼綘寰堝彲鑳戒笉鎯宠缃寚鍚憇ettings妯″潡鐨勭幆澧冨彉閲忋
In these cases, you can configure Djangos settings manually. Do this by calling django.conf.settings.configure() . Heres an example:
杩欏湪浜涙儏鍐典笅锛屼綘鍙互鎵嬪伐璁剧疆Django鐨剆ettings锛岄氳繃 django.conf.settings.configure() 銆傝繖閲屾湁涓涓緥瀛愶細
from django.conf import settings settings.configure( DEBUG = True, TEMPLATE_DEBUG = True, TEMPLATE_DIRS = [ '/home/web-apps/myapp', '/home/web-apps/base', ] )
Pass configure() as many keyword arguments as youd like, with each keyword argument representing a setting and its value. Each argument name should be all uppercase, with the same name as the settings described earlier. If a particular setting is not passed to configure() and is needed at some later point, Django will use the default setting value.
Configuring Django in this fashion is mostly necessary and, indeed, recommended when youre using a piece of the framework inside a larger application.
鎸夌収姝や竴棰ㄦ牸瑷疆 Django 瀵﹀墖鏈夊叾蹇呰,灏ゅ叾鐣跺湪涓鍊嬭純澶х殑鎳夌敤绋嬪紡瑁″鐢ㄤ竴閮ㄥ垎妗嗘灦鏅.
Consequently, when configured via settings.configure() , Django will not make any modifications to the process environment variables. (See the explanation of TIME_ZONE later in this appendix for why this would normally occur.) Its assumed that youre already in full control of your environment in these cases.
If youd like default values to come from somewhere other than django.conf.global_settings , you can pass in a module or class that provides the default settings as the default_settings argument (or as the first positional argument) in the call to configure() .
濡傛灉浣犳兂浠 django.conf.global_settings 浠ュ鐨勫湴鏂硅幏寰楅粯璁よ缃紝浣犲彲浠ヤ紶鍏ヤ竴涓彁渚涢粯璁よ缃綋浣 default_settings 鐨勫弬鏁帮紙鎴栬呭綋浣滅涓涓弬鏁) 鍒板洖璋冨嚱鏁 configure()銆
In this example, default settings are taken from myapp_defaults , and the DEBUG setting is set to True , regardless of its value in myapp_defaults :
鍦ㄤ笅闈㈢殑鍒楀瓙涓紝榛樿璁剧疆鏄槸浠巑yapp_defaults鑾峰彇鐨勶紝涓擠EBUG鏄缃负True, regardless of its value in myapp_defaults :
from django.conf import settings from myapp import myapp_defaults settings.configure(default_settings=myapp_defaults, DEBUG=True)
The following example, which uses myapp_defaults as a positional argument, is equivalent:
涓嬮潰鐨勪緥瀛愭槸绛変环鐨勶細
settings.configure(myapp_defaults, DEBUG = True)
Normally, you will not need to override the defaults in this fashion. The Django defaults are sufficiently tame that you can safely use them. Be aware that if you do pass in a new default module, it entirely replaces the Django defaults, so you must specify a value for every possible setting that might be used in that code you are importing. Check in django.conf.settings.global_settings for the full list.
涓鑸岃█,鎮ㄧ劇闇鏀硅畩鍏堕爯瑷. 鎮ㄦ噳瑭插彲浠ュ畨鍏ㄥ钩闋嗗湴浣跨敤 Django 鐨勯爯瑷. 瑕佹敞鎰忕殑鏄,涓鏃﹀偝閫蹭竴绲勬柊鐨勯爯瑷ā绲,鎵鏈夌殑 Django 闋愯ō璩囨枡灏囨渻鍏ㄩ儴琚*鍙栦唬*,鍥犳,蹇呴爤鍦ㄨ几鍏ョ▼寮忕⒓鏅,閲濆皪姣忎竴鍊嬪彲鑳界殑瑷畾绲﹀. 璜嬫煡闁 django.conf.settings.global_settings 浜嗚В鎵鏈夌殑鐩搁棞瑷畾.
If youre not setting the DJANGO_SETTINGS_MODULE environment variable, you must call configure() at some point before using any code that reads settings.
濡傛灉浣犳病鏈夎缃甡`DJANGO_SETTINGS_MODULE``鐜鍙橀噺锛屼綘蹇呴』鍦ㄤ娇鐢ㄤ换浣曡鍙栬缃殑浠g爜涔嬪墠鐨勬煇澶勮皟鐢╜`configure()`` 鏂规硶銆
If you dont set DJANGO_SETTINGS_MODULE and dont call configure() , Django will raise an EnvironmentError exception the first time a setting is accessed.
濡傛灉浣犳病鏈夎缃甡`DJANGO_SETTINGS_MODULE`` 涔熸病鏈夎皟鐢╜`configure()``锛屽綋绗竴娆℃煇涓猻etting琚闂椂锛孌jango 灏嗕細鍑虹幇``EnvironmentError`` 寮傚父銆
If you set DJANGO_SETTINGS_MODULE , access settings values somehow, and then call configure() , Django will raise an EnvironmentError stating that settings have already been configured.
Also, its an error to call configure() more than once, or to call configure() after any setting has been accessed.
鍙﹀锛屼笉姝竴娆℃垨鍦ㄤ换浣晄etting宸茬粡琚闂箣鍚庤皟鐢╜`configure()`` 閮芥槸閿欒鐨勩
It boils down to this: use exactly one of either configure() or DJANGO_SETTINGS_MODULE . Not both, and not neither.
The following sections consist of a full list of all available settings, in alphabetical order, and their default values.
涓嬮潰绔犺妭鍖呮嫭鍏ㄩ儴鏈夋晥setting椤癸紙鎸夊瓧姣嶉『搴忔帓搴忥級鍙婂叾榛樿鍊肩殑涓涓畬鏁村垪琛ㄣ
Default : {} (empty dictionary)
榛樿 : {} (empty dictionary)
This is a dictionary mapping "app_label.model_name" strings to functions that take a model object and return its URL. This is a way of overriding get_absolute_url() methods on a per-installation basis. Heres an example:
000000000000000000000000000000
ABSOLUTE_URL_OVERRIDES = { 'blogs.weblog': lambda o: "/blogs/%s/" % o.slug, 'news.story': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug), }
Note that the model name used in this setting should be all lowercase, regardless of the case of the actual model class name.
Default : () (empty list)
榛樿 : () (empty list)
This setting is used for admin site settings modules. It should be a tuple of settings modules (in the format 'foo.bar.baz' ) for which this site is an admin.
The admin site uses this in its automatically introspected documentation of models, views, and template tags.
Default : '/media/'
榛樿 : '/media/'
This setting is the URL prefix for admin media: CSS, JavaScript, and images. Make sure to use a trailing slash.
姝よ缃槸鐢ㄦ潵璁剧疆绠$悊妯″紡鐨勯潤鎬佹枃浠讹紙鍖呮嫭CSS锛孞avaScript鍜屽浘鍍忥級URL鐨勫墠缂銆傛敞鎰忚浣跨敤鏂滅嚎
Default : () (empty tuple)
榛樿 : () (empty tuple)
This is a tuple that lists people who get code error notifications. When DEBUG=False and a view raises an exception, Django will email these people with the full exception information. Each member of the tuple should be a tuple of (Full name, e-mail address), for example:
(('John', 'john@example.com'), ('Mary', 'mary@example.com'))
Note that Django will email all of these people whenever an error happens.
姣忓綋涓涓敊璇鎹曡幏鐨勬椂鍊欙紝Django 灏嗗彂閫佺粰鎵鏈夎繖浜涗汉
Default : () (empty tuple)
榛樿 : () (empty tuple)
This is a tuple of strings representing allowed prefixes for the {% ssi %} template tag. This is a security measure, so that template authors cant access files that they shouldnt be accessing.
For example, if ALLOWED_INCLUDE_ROOTS is ('/home/html', '/var/www') , then {% ssi /home/html/foo.txt %} would work, but {% ssi /etc/passwd %} wouldnt.
Default : True
榛樿 : True
This setting indicates whether to append trailing slashes to URLs. This is used only if CommonMiddleware is installed (see Chapter 15). See also PREPEND_WWW .
褰撴璁剧疆椤逛负True鐨勬椂鍊欙紝绯荤粺浼氳嚜鍔ㄥ湪URL鐨勫熬閮ㄥ姞涓婁竴涓弽鏂滄潬’/’銆傝繖涓缃」浠呬粎鍦ㄥ畨瑁呬簡``CommonMiddleware``鐨勭姸鎬佷笅浣跨敤锛堣瑙佺15绔狅級鐨刞`PREPEND_WWW``
Default : 'simple://'
榛樿 : 'simple://'
This is the cache back-end to use (see Chapter 13).
鎸囧畾浣跨敤鐨勭紦瀛樺悗绔紙瑙佺 13 绔狅級銆
Default : '' (empty string)
榛樿 : '' (empty string)
This is the cache key prefix that the cache middleware should use (see Chapter 13).
Default : '' (empty string)
榛樿 : '' (empty string)
This setting indicates which database back-end to use: 'postgresql_psycopg2' , 'postgresql' , 'mysql' , 'mysql_old' or 'sqlite3' .
璇ヨ缃敤浜庢寚瀹氫娇鐢ㄤ笅鍒楀摢绉嶆暟鎹簱浣滀负瀛樺偍鍚庣: 'postgresql_psycopg2' , 'postgresql' , 'mysql' , 'mysql_old' or 'sqlite3' .
Default : '' (empty string)
榛樿 : '' (empty string)
This setting indicates which host to use when connecting to the database. An empty string means localhost . This is not used with SQLite.
璇ヨ缃寚瀹氳繛鎺ユ暟鎹簱鏃舵墍浣跨敤鐨勪富鏈恒傜┖瀛楃涓茶〃绀篳`localhost`` 銆傚鏋滀綘浣跨敤SQLite锛屽垯涓嶇敤璁剧疆璇ュ笺
If this value starts with a forward slash ('/' ) and youre using MySQL, MySQL will connect via a Unix socket to the specified socket:
濡傛灉浣犲湪浣跨敤MySQL锛岃岃繖涓兼槸浠ュ弽鏂滅嚎('/' )寮澶达紝閭d箞MySQL灏嗛氳繃鎸囧畾鐨刄nix socket杩涜杩炴帴锛
DATABASE_HOST = '/var/run/mysql'
If youre using MySQL and this value doesnt start with a forward slash, then this value is assumed to be the host.
濡傛灉浣犲湪浣跨敤MySQL锛岃岃繖涓煎張娌℃湁浠ュ弽鏂滅嚎寮澶达紝閭d箞杩欎釜鍊煎氨琚涓烘槸涓绘満銆
Default : '' (empty string)
榛樿 : '' (empty string)
This is the name of the database to use. For SQLite, its the full path to the database file.
璇ヨ缃负鎵浣跨敤鏁版嵁搴撶殑鍚嶇О銆傚鏋滀娇鐢⊿QLite锛岃璁剧疆涓烘暟鎹簱鏂囦欢鐨勫畬鏁磋矾寰勩
Default : {} (empty dictionary)
榛樿 : {} (empty dictionary)
This is extra parameters to use when connecting to the database. Consult the back-end modules document for available keywords.
Default : '' (empty string)
榛樿 : '' (empty string)
This setting is the password to use when connecting to the database. It is not used with SQLite.
璇ヨ缃负鏁版嵁搴撹繛鎺ュ瘑鐮併傚鏋滀娇鐢⊿QLite锛屽垯涓嶇敤璁剧疆銆
Default : '' (empty string)
榛樿 : '' (empty string)
This is the port to use when connecting to the database. An empty string means the default port. It is not used with SQLite.
杩欐槸鐢ㄦ潵杩炴帴鏁版嵁搴撶殑绔彛. 绌哄瓧绗︿唬琛ㄧ己鐪佺鍙. SQLite 涓嶇敤璁剧疆.
Default : '' (empty string)
榛樿 : '' (empty string)
This setting is the username to use when connecting to the database. It is not used with SQLite.
璇ヨ缃负杩炴帴鏁版嵁搴撶殑鐢ㄦ埛鍚嶃傚綋浣跨敤 SQLite 鏃舵棤鏁堛
Default : 'N j, Y' (e.g., Feb. 4, 2003 )
榛樿 : 'N j, Y' (e.g., Feb. 4, 2003 )
This is the default formatting to use for date fields on Django admin change-list pages and, possibly, by other parts of the system. It accepts the same format as the now tag (see Appendix F, Table F-2).
See also DATETIME_FORMAT , TIME_FORMAT , YEAR_MONTH_FORMAT , and MONTH_DAY_FORMAT .
鍙﹁ DATETIME_FORMAT , TIME_FORMAT , YEAR_MONTH_FORMAT , 鍜 MONTH_DAY_FORMAT .
Default : 'N j, Y, P' (e.g., Feb. 4, 2003, 4 p.m. )
榛樿 : 'N j, Y, P' (渚嬪, Feb. 4, 2003, 4 p.m. )
This is the default formatting to use for datetime fields on Django admin change-list pages and, possibly, by other parts of the system. It accepts the same format as the now tag (see Appendix F, Table F-2).
See also DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , YEAR_MONTH_FORMAT , and MONTH_DAY_FORMAT .
鍙﹁ DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , YEAR_MONTH_FORMAT , 鍜 MONTH_DAY_FORMAT .
Default : False
榛樿 : False
This setting is a Boolean that turns debug mode on and off.
杩欎釜璁剧疆椤规槸涓涓爣绀篸ebug寮鍏崇殑甯冨皵鍊笺
If you define custom settings, django/views/debug.py has a HIDDEN_SETTINGS regular expression that will hide from the DEBUG view anything that contains 'SECRET , PASSWORD , or PROFANITIES' . This allows untrusted users to be able to give backtraces without seeing sensitive (or offensive) settings.
Still, note that there are always going to be sections of your debug output that are inappropriate for public consumption. File paths, configuration options, and the like all give attackers extra information about your server. Never deploy a site with DEBUG turned on.
Default : 'utf-8'
榛樿 : 'utf-8'
This is the default charset to use for all HttpResponse objects, if a MIME type isnt manually specified. It is used with DEFAULT_CONTENT_TYPE to construct the Content-Type header. See Appendix H for more about HttpResponse objects.
Default : 'text/html'
榛樿 : 'text/html'
This is the default content type to use for all HttpResponse objects, if a MIME type isnt manually specified. It is used with DEFAULT_CHARSET to construct the Content-Type header. See Appendix H for more about HttpResponse objects.
Default : 'webmaster@localhost'
榛樿 : 'webmaster@localhost'
This is the default email address to use for various automated correspondence from the site manager(s).
Default : () (empty tuple)
榛樿 : () (empty tuple)
This is a list of compiled regular expression objects representing User-Agent strings that are not allowed to visit any page, systemwide. Use this for bad robots/crawlers. This is used only if CommonMiddleware is installed (see Chapter 15).
Default : 'localhost'
榛樿 : 'localhost'
This is the host to use for sending email. See also EMAIL_PORT .
Default : '' (empty string)
榛樿 : '' (empty string)
This is the password to use for the SMTP server defined in EMAIL_HOST . This setting is used in conjunction with EMAIL_HOST_USER when authenticating to the SMTP server. If either of these settings is empty, Django wont attempt authentication.
See also EMAIL_HOST_USER .
鍙﹁ EMAIL_HOST_USER .
Default : '' (empty string)
榛樿 : '' (empty string)
This is the username to use for the SMTP server defined in EMAIL_HOST . If its empty, Django wont attempt authentication. See also EMAIL_HOST_PASSWORD .
Default : 25
榛樿 : 25
This is the port to use for the SMTP server defined in EMAIL_HOST .
Default : '[Django] '
榛樿 : '[Django] '
This is the subject-line prefix for email messages sent with django.core.mail.mail_admins or django.core.mail.mail_managers . Youll probably want to include the trailing space.
Default : () (empty tuple)
榛樿 : () (empty tuple)
This is a list of locations of the fixture data files, in search order. Note that these paths should use Unix-style forward slashes, even on Windows. It is used by Djangos testing framework, which is covered online at http://www.djangoproject.com/documentation/0.96/testing/.
Default : ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')
榛樿 : ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')
See also IGNORABLE_404_STARTS and Error reporting via e-mail .
鍙﹁ IGNORABLE_404_STARTS 鍜 Error reporting via e-mail .
Default : ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
榛樿 : ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
This is a tuple of strings that specify beginnings of URLs that should be ignored by the 404 emailer. See also SEND_BROKEN_LINK_EMAILS and IGNORABLE_404_ENDS .
Default : () (empty tuple)
榛樿 : () (empty tuple)
A tuple of strings designating all applications that are enabled in this Django installation. Each string should be a full Python path to a Python package that contains a Django application. See Chapter 5 for more about applications.
Default : () (empty tuple)
榛樿 : () (empty tuple)
A tuple of IP addresses, as strings, that
See debug comments, when DEBUG is True
Receive X headers if the XViewMiddleware is installed (see Chapter 15)
Default : '/usr/bin/jing'
榛樿 : '/usr/bin/jing'
This is the path to the Jing executable. Jing is a RELAX NG validator, and Django uses it to validate each XMLField in your models. See http://www.thaiopensource.com/relaxng/jing.html.
Default : 'en-us'
榛樿 : 'en-us'
This is a string representing the language code for this installation. This should be in standard language format for example, U.S. English is "en-us" . See Chapter 18.
Default : A tuple of all available languages. This list is continually growing and any copy included here would inevitably become rapidly out of date. You can see the current list of translated languages by looking in django/conf/global_settings.py .
The list is a tuple of two-tuples in the format (language code, language name) for example, ('ja', 'Japanese') . This specifies which languages are available for language selection. See Chapter 18 for more on language selection.
Generally, the default value should suffice. Only set this setting if you want to restrict language selection to a subset of the Django-provided languages.
If you define a custom LANGUAGES setting, its OK to mark the languages as translation strings, but you should never import django.utils.translation from within your settings file, because that module in itself depends on the settings, and that would cause a circular import.
The solution is to use a dummy gettext() function. Heres a sample settings file:
gettext = lambda s: s LANGUAGES = ( ('de', gettext('German')), ('en', gettext('English')), )
With this arrangement, make-messages.py will still find and mark these strings for translation, but the translation wont happen at runtime so youll have to remember to wrap the languages in the real gettext() in any code that uses LANGUAGES at runtime.
Default : () (empty tuple)
榛樿 : () (empty tuple)
This tuple is in the same format as ADMINS that specifies who should get broken-link notifications when SEND_BROKEN_LINK_EMAILS=True .
Default : '' (empty string)
榛樿 : '' (empty string)
This is an absolute path to the directory that holds media for this installation (e.g., "/home/media/media.lawrence.com/" ). See also MEDIA_URL .
Default : '' (empty string)
榛樿 : '' (empty string)
This URL handles the media served from MEDIA_ROOT (e.g., "http://media.lawrence.com" ).
Note that this should have a trailing slash if it has a path component:
Correct : "http://www.example.com/static/"
姝g‘ : "http://www.example.com/static/"
Incorrect : "http://www.example.com/static"
閿欒 : "http://www.example.com/static"
Default :
榛樿 :
("django.contrib.sessions.middleware.SessionMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.doc.XViewMiddleware")
This is a tuple of middleware classes to use. See Chapter 15.
Default : 'F j'
榛樿 : 'F j'
This is the default formatting to use for date fields on Django admin change-list pages and, possibly, by other parts of the system in cases when only the month and day are displayed. It accepts the same format as the now tag (see Appendix F, Table F-2).
For example, when a Django admin change-list page is being filtered by a date, the header for a given day displays the day and month. Different locales have different formats. For example, U.S. English would have January 1, whereas Spanish might have 1 Enero.
See also DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , and YEAR_MONTH_FORMAT .
鍙﹁ DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , 鍜 YEAR_MONTH_FORMAT .
Default : False
榛樿 : False
This setting indicates whether to prepend the www. subdomain to URLs that dont have it. This is used only if CommonMiddleware is installed (see the Chapter 15). See also APPEND_SLASH .
This is a tuple of profanities, as strings, that will trigger a validation error when the hasNoProfanities validator is called.
We dont list the default values here, because that might bring the MPAA ratings board down on our heads. To view the default values, see the file django/conf/global_settings.py .
Default : Not defined
榛樿 : Not defined
This is a string representing the full Python import path to your root URLconf (e.g., "mydjangoapps.urls" ). See Chapter 3.
Default : (Generated automatically when you start a project)
榛樿 : (褰撲綘鍒涘缓涓涓」鐩椂鑷姩鐢熸垚)
This is a secret key for this particular Django installation. It is used to provide a seed in secret-key hashing algorithms. Set this to a random string the longer, the better. django-admin.py startproject creates one automatically and most of the time you wont need to change it
Default : False
榛樿 : False
This setting indicates whether to send an email to the MANAGERS each time somebody visits a Django-powered page that is 404-ed with a nonempty referer (i.e., a broken link). This is only used if CommonMiddleware is installed (see Chapter 15). See also IGNORABLE_404_STARTS and IGNORABLE_404_ENDS .
Default : Not defined.
榛樿 : Not defined.
Serialization is a feature still under heavy development. Refer to the online documentation at http://www.djangoproject.com/documentation/0.96/serialization/ for more information.
Default : 'root@localhost'
榛樿 : 'root@localhost'
This is the email address that error messages come from, such as those sent to ADMINS and MANAGERS .
Default : 1209600 (two weeks, in seconds)
榛樿 : 1209600 (涓ゅ懆锛屼互绉掕)
This is the age of session cookies, in seconds. See Chapter 12.
Default : None
榛樿 : None
This is the domain to use for session cookies. Set this to a string such as ".lawrence.com" for cross-domain cookies, or use None for a standard domain cookie. See Chapter 12.
Default : 'sessionid'
榛樿 : 'sessionid'
This is the name of the cookie to use for sessions; it can be whatever you want. See Chapter 12.
Default : False
榛樿 : False
This setting indicates whether to use a secure cookie for the session cookie. If this is set to True , the cookie will be marked as secure, which means browsers may ensure that the cookie is only sent under an HTTPS connection. See Chapter 12.
Default : False
榛樿 : False
This setting indicates whether to expire the session when the user closes his browser. See Chapter 12.
Default : False
榛樿 : False
This setting indicates whether to save the session data on every request. See Chapter 12.
Default : Not defined
榛樿 : Not defined
This is the ID, as an integer, of the current site in the django_site database table. It is used so that application data can hook into specific site(s) and a single database can manage content for multiple sites. See Chapter 14.
杩欏氨鏄湪鈥渄jango_site鈥濇暟鎹簱琛ㄤ腑褰撳墠缃戠珯鐨勬暣鏁癐D銆傚畠甯哥敤浜庡簲鐢ㄧ▼搴忔暟鎹兘澶熸寕閽╁埌鎸囧畾鐨勭綉绔欙紝鎴栧崟涓暟鎹簱涓婅兘绠$悊澶氫釜缃戠珯鐨勫唴瀹广傚弬瑙佺14绔犮
Default :
榛樿 :
("django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n")
This is a tuple of callables that are used to populate the context in RequestContext . These callables take a request object as their argument and return a dictionary of items to be merged into the context. See Chapter 10.
Default : False
榛樿 : False
This Boolean turns template debug mode on and off. If it is True , the fancy error page will display a detailed report for any TemplateSyntaxError . This report contains the relevant snippet of the template, with the appropriate line highlighted.
Note that Django only displays fancy error pages if DEBUG is True , so youll want to set that to take advantage of this setting.
See also DEBUG .
鍙﹁ DEBUG .
Default : () (empty tuple)
榛樿 : () (empty tuple)
This is a list of locations of the template source files, in search order. Note that these paths should use Unix-style forward slashes, even on Windows. See Chapters 4 and 10.
杩欐槸涓涓牴鎹悳绱㈡帓搴忕殑妯℃澘婧愭枃浠剁殑浣嶇疆鍒楄〃銆傛敞鎰忥紝杩欎簺璺緞搴旇浣跨敤Unix椋庢牸鐨勫垎鍓茬锛屽嵆浣垮湪Windows涓娿傚弬鍔犵4鍜10绔犮
Default : ('django.template.loaders.filesystem.load_template_source',)
榛樿 : ('django.template.loaders.filesystem.load_template_source',)
This is a tuple of callables (as strings) that know how to import templates from various sources. See Chapter 10.
Default : '' (Empty string)
榛樿 : '' (Empty string)
This is output, as a string, that the template system should use for invalid (e.g., misspelled) variables. See Chapter 10.
Default : 'django.test.simple.run_tests'
榛樿 : 'django.test.simple.run_tests'
This is the name of the method to use for starting the test suite. It is used by Djangos testing framework, which is covered online at http://www.djangoproject.com/documentation/0.96/testing/.
杩欐槸鐢ㄤ簬鍚姩娴嬭瘯濂椾欢鐨勬柟娉曞悕绉般傚畠鐢ㄥ湪Django娴嬭瘯妗嗘灦涓紝鍙傝http://www.djangoproject.com/documentation/0.96/testing 銆
Default : None
榛樿 : None
This is the name of database to use when running the test suite. If a value of None is specified, the test database will use the name 'test_' + settings.DATABASE_NAME . See the documentation for Djangos testing framework, which is covered online at http://www.djangoproject.com/documentation/0.96/testing/.
杩欐槸鐢ㄤ簬鎵ц娴嬭瘯濂椾欢鐨勬暟鎹悕绉般傚鏋滆鍊间负None, 閭d箞娴嬭瘯鏁版嵁搴撳皢浼氫娇鐢ㄥ悕绉’test_‘ + settings.DATABASE_NAME銆傚弬瑙丏jango娴嬭瘯妗嗘灦鐨勬枃妗o紝浣嶄簬http://www.djangoproject.com/documentation/0.96/testing/ 銆
Default : 'P' (e.g., 4 p.m. )
榛樿 : 'P' (e.g., 4 p.m. )
This is the default formatting to use for time fields on Django admin change-list pages and, possibly, by other parts of the system. It accepts the same format as the now tag (see Appendix F, Table F-2).
See also DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , YEAR_MONTH_FORMAT , and MONTH_DAY_FORMAT .
鍙﹁ DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , YEAR_MONTH_FORMAT , 鍜 MONTH_DAY_FORMAT .
Default : 'America/Chicago'
榛樿 : 'America/Chicago'
This is a string representing the time zone for this installation. Time zones are in the Unix-standard zic format. One relatively complete list of time zone strings can be found at http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE.
姝ゅ瓧绗︿覆琛ㄧず瀹夎鐨勬椂鍖恒傛椂鍖轰负Unix鏍囧噯鐨剒ic鏍煎紡銆傚湪http://www.postgresql.org/docs/8.1/static/dateime-keywords.html#DATETIME-TIMEZONE-SET-TABLE涓婃湁涓涓浉瀵瑰畬鏁寸殑鏃跺尯瀛楃涓插垪琛ㄣ
This is the time zone to which Django will convert all dates/times not necessarily the time zone of the server. For example, one server may serve multiple Django-powered sites, each with a separate time-zone setting.
杩欐槸Django杞崲鍖呮嫭鏈嶅姟鍣ㄦ椂鍖哄湪鍐呯殑鎵鏈夋棩鏈燂紡鏃堕棿鏃舵墍鐢ㄧ殑鏃跺尯銆備緥濡傦紝涓涓湇鍔″櫒鍙互鎵樼澶氫釜Django绔欑偣锛屾瘡涓珯鐐规湁涓涓嫭绔嬬殑鏃跺尯璁剧疆銆
Normally, Django sets the os.environ['TZ'] variable to the time zone you specify in the TIME_ZONE setting. Thus, all your views and models will automatically operate in the correct time zone. However, if youre using the manually configuring settings (described above in the section titled Using Settings Without Setting DJANGO_SETTINGS_MODULE), Django will not touch the TZ environment variable, and it will be up to you to ensure your processes are running in the correct environment.
Note
娉ㄦ剰
Django cannot reliably use alternate time zones in a Windows environment. If youre running Django on Windows, this variable must be set to match the system time zone.
Django涓嶈兘鍙潬鍦颁娇鐢╓indows鐜閲岀殑鍙夋椂鍖恒傚鏋滀綘鍦╓indows涓婅繍琛孌jango锛岃繖涓彉閲忓繀椤昏缃负涓庣郴缁熸椂鍖轰竴鑷淬
Default : Django/<version> (http://www.djangoproject.com/)
榛樿 : Django/<version> (http://www.djangoproject.com/)
This is the string to use as the User-Agent header when checking to see if URLs exist (see the verify_exists option on URLField ; see Appendix B).
杩欐槸褰撴鏌rl鏄惁瀛樺湪鏃剁敤浜庘淯ser-Agent鈥濈殑瀛楃涓诧紙 鍙傝鈥淯RLField鈥濈殑鈥渧erify_exists鈥濋夐」锛涘弬瑙侀檮褰旴锛夈
Default : False
榛樿 : False
This Boolean specifies whether to output the ETag header. It saves bandwidth but slows down performance. This is only used if CommonMiddleware is installed (see Chapter 15).
姝ら昏緫鍊兼寚瀹氭槸鍚﹁緭鍑篍Tag鍓嶇紑銆傝繖浼氳妭鐪佸甫瀹戒絾鏄檷浣庢ц兘銆備竴鑸彧鏈夊綋瀹夎浜嗘椂鎵嶄娇鐢ㄦ閫夐」锛堝弬瑙佺15绔狅級銆
Default : True
榛樿 : True
This Boolean specifies whether Djangos internationalization system (see Chapter 18) should be enabled. It provides an easy way to turn off internationalization, for performance. If this is set to False , Django will make some optimizations so as not to load the internationalization machinery.
姝ら昏緫鍊兼寚瀹欴jango鍥介檯鍖栫郴缁燂紙鍙傝绗18绔狅級鏄惁鍙敤銆傝繖鎻愪緵浜嗕竴涓洜涓烘ц兘鑰屽叧闂浗闄呭寲鐨勭畝鍗曟柟娉曘傚鏋滄鍊艰涓衡淔alse鈥,Django灏嗕細鍋氫竴浜涗紭鍖栦互鏇夸唬鏈姞杞界殑鍥介檯鍖栨満鍒躲
Default : 'F Y'
榛樿 : 'F Y'
This is the default formatting to use for date fields on Django admin change-list pages and, possibly, by other parts of the system in cases when only the year and month are displayed. It accepts the same format as the now tag (see Appendix F).
杩欐槸榛樿鏍煎紡锛岀敤浜嶥jango绠$悊鍙樻洿鍒楄〃椤甸潰鐨勬棩鏈熷煙锛屽苟涓旀湁鍙兘锛屼篃鐢ㄤ簬绯荤粺鍏朵粬閮ㄥ垎鐨勫彧鏄剧ず骞存湀鐨勬儏鍐点傗渘ow鈥濇爣绛炬帴鍙楃浉鍚岀殑鏍煎紡銆傦紙鍙傝闄勫綍F锛夈
For example, when a Django admin change-list page is being filtered by a date drill-down, the header for a given month displays the month and the year. Different locales have different formats. For example, U.S. English would use January 2006, whereas another locale might use 2006/January.
渚嬪锛屽綋涓涓狣jango绠$悊鍙樻洿鍒楄〃涔熻涓涓棩鏈熻繃婊ゆ椂锛岀粰鍑虹殑鏈堜唤鍓嶇紑浼氭樉绀哄嚭骞存湀銆備笉鍚岀殑鍦板尯鏈変笉鍚岀殑鏍煎紡锛屾瘮濡傜編鍥借嫳璇細浣跨敤January 2006锛岃屽叾浠栧湴鍖哄彲鑳戒娇鐢2006/January銆
See also DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , and MONTH_DAY_FORMAT .
鍙﹁ DATE_FORMAT , DATETIME_FORMAT , TIME_FORMAT , 鍜 MONTH_DAY_FORMAT .
鍏充簬鏈瘎娉ㄧ郴缁
鏈珯浣跨敤涓婁笅鏂囧叧鑱旂殑璇勬敞绯荤粺鏉ユ敹闆嗗弽棣堜俊鎭備笉鍚屼簬涓鑸鏁寸珷鍋氳瘎娉ㄧ殑鍋氭硶锛 鎴戜滑鍏佽浣犲姣忎竴涓嫭绔嬬殑鈥滄枃鏈潡鈥濆仛璇勬敞銆備竴涓滄枃鏈潡鈥濈湅璧锋潵鏄繖鏍风殑锛
涓涓滄枃鏈潡鈥濇槸涓涓钀斤紝涓涓垪琛ㄩ」锛屼竴娈典唬鐮侊紝鎴栬呭叾浠栦竴灏忔鍐呭銆 浣犻変腑瀹冧細楂樹寒搴︽樉绀:
瑕佸鏂囨湰鍧楀仛璇勬敞锛屼綘鍙渶瑕佺偣鍑诲畠鏃佽竟鐨勬爣璇嗗潡:
鎴戜滑浼氫粩缁嗛槄璇绘瘡涓瘎璁猴紝濡傛灉鍙兘鐨勮瘽鎴戜滑涔熶細鎶婅瘎娉ㄨ冭檻鍒版湭鏉ョ殑鐗堟湰涓幓:
濡傛灉浣犳効鎰忎綘鐨勮瘎娉ㄨ閲囩敤锛岃纭繚鐣欎笅浣犵殑鍏ㄥ悕 (娉ㄦ剰涓嶆槸鏄电О鎴栫畝绉帮級
Many, many thanks to Jack Slocum; the inspiration and much of the code for the comment system comes from Jack's blog, and this site couldn't have been built without his wonderful
YAHOO.ext
library. Thanks also to Yahoo for YUI itself.