django - 应用程序不在INSTALLED_APPS中,但其views.py正在运行 [英] django - app not in INSTALLED_APPS but its views.py is running

查看:315
本文介绍了django - 应用程序不在INSTALLED_APPS中,但其views.py正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个应用程式我想根据settings.py运行它,这意味着我有多个settings_x.py。我运行服务器像这样:

  python manage.py runserver --settings = myproj.settings_1.py 



如果我运行

  python manage.py runserver 

它应该采用默认settings.py,我没有在 INSTALLED_APPS ,它应该给我错误的说,模块app1不存在,因为

 #urls.py 
urlpatterns = patterns('app1.views',#< ---- app1不在settings.py
url(r'^ $','startpage',name ='startpage '),

但是它将要 startpage function inside app1.views



为什么会这样?我错过了什么吗?

解决方案

没有理由不这样做。视图可以来自任何地方,而不必在一个应用程序中:他们只需要从Python路径访问。


I having multiple apps. I want to run them according to settings.py which means I have multiple settings_x.py. I run server e.g. like this:

python manage.py runserver --settings=myproj.settings_1.py

for app1.

If I run

python manage.py runserver

it should take the default settings.py where I didnot define any app in INSTALLED_APPS, and It should give me error saying, that the module app1 doesnot exist because of

#urls.py
urlpatterns = patterns('app1.views',#<---- app1 isn't in the settings.py
   url(r'^$', 'startpage', name='startpage'),
)

But it is going to startpage function inside app1.views.

why is this? am I missing something?

解决方案

There's no reason why it wouldn't. Views can come from anywhere, and don't have to be in an app at all: they just need to be accessible from the Python path.

这篇关于django - 应用程序不在INSTALLED_APPS中,但其views.py正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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