Django 1.4新项目文件夹结构强制项目前缀? [英] Django 1.4 new project folder structure forces project prefixes?
问题描述
使用django 1.4,并看到当您使用 startproject
时,它现在在您的项目中创建一个名称相同的文件夹。
-myproject /
manage.py
myproject /
settings.py
urls.py
以前对于我的URL,我可以输入
ROOT_URLCONF ='urls'
但是那不再工作了。我现在应该用这个项目名称前缀吗?即
ROOT_URLCONF ='myproject.urls'
-
在我的 urls.py
我会导入设置,但现在我必须用从myproject导入设置
。
我认为前缀变量与项目名称是违反django标准,因为它破坏了可重用性?
ROOT_URLCONF
与您的项目名称: ROOT_URLCONF ='myproject.urls'
您不应直接导入设置(请参阅< a href =https://docs.djangoproject.com/en/dev/topics/settings/#using-settings-in-python-code> 使用Python代码中的设置 )。相反,请使用以下内容,它适用于旧的和新的项目布局。
从django.conf导入设置
Using django 1.4 and have seen that when you use startproject
it now creates a folder within your project with the same name.
-myproject/
manage.py
myproject/
settings.py
urls.py
Previously for my urls I could input
ROOT_URLCONF = 'urls'
But that no longer works. Am I now supposed to prefix this with project name? i.e.
ROOT_URLCONF = 'myproject.urls'
--
In my urls.py
I'd import settings but now I have to prefix it with from myproject import settings
.
I thought prefixing variables with the project name was against django standards as it breaks reuseability?
Yes, prefix ROOT_URLCONF
with your project name:
ROOT_URLCONF = 'myproject.urls'
You shouldn't import settings directly anyway (see Using settings in Python code). Instead, use the following, which works for both the old and new project layouts.
from django.conf import settings
这篇关于Django 1.4新项目文件夹结构强制项目前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!