Django 1.4新项目文件夹结构强制项目前缀? [英] Django 1.4 new project folder structure forces project prefixes?

查看:102
本文介绍了Django 1.4新项目文件夹结构强制项目前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用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

Documented change here

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆