我有一个Django项目结构,如下所示:
siteDirectory
-manage.py
-mySite
-__init.py
-settings.py
-urls.py (1)
-public
-__init__.py
-urls.py (2)
-app1
-models.py
-views.py
-urls.py (3)
-app2
-app3
-urls.py
(为简洁起见,省略了一些文件。)
我已经成功运行了我的网站,我的模型按计划运行。然后我去设置一个URL方案,我可以给出这样的URL:localhost/app1/5
其中5
是模型对象的ID。这类似于Django教程(https://docs.djangoproject.com/en/1.8/intro/tutorial03/)的“编写更多视图”部分。但是,当我实现它时,我收到404错误,并且我的URL模式未在我的文件中定义。这些是我拥有的URL文件(它们与结构中相应的文件编号匹配)
urls.py(1)
from public import urls as public_urls
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
# Public-facing site
url(r'', include(public_urls))
]
urls.py(2)
from app1 import urls as app_one_urls
from app2 import views as app_two_views
from app3 import views as app_three_views
# URLs
urlpatterns = [
url(r'^app1$', include(app_one_urls)),
url(r'^app2$', app_two_views.main)
url(r'^app3$', app_three_views.main),
]
urls.py(3)
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.main, name='index'),
url(r'^(?P<someObject_id>[0-9]+)/$', views.someObject, name='someObject'),
]
我可以成功访问我的所有应用,但只有someObject
GET不起作用。是什么导致了这个404错误?