基本上使用 django 并且它一直告诉我这段代码中存在语法错误:
from django.conf.urls import patterns, url
from venues import views
urlpatterns = patterns('',
url(r'^$', views.index, name = 'index'),
# ex /venues/3
url(r'^(?P<venue_id>\d+)/$', views.detail, name='detail'),
# ex: /venues/3/events
url(r'^(?P<venue_id>\d+)/events/$', views.events, name='events')
)
具体来说,它似乎告诉我:
from venues import views
行不正确。
但是我的场所/views.py 看起来像:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello this is the home page!")
def detail(request, venue_id):
return HttpResponse("You're looking at Venue %s.", % venue_id)
def events(request, venue_id):
return HttpResponse("You're looking at events at venue %s.", % venue_id)
所以该文件存在并且似乎运行良好,直到我开始在 urls.py 中使用场地 ID
哦,只是为了衡量我的主要 urls.py 看起来像:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Comedy.views.home', name='home'),
# url(r'^Comedy/', include('Comedy.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^venues/', include('venues.urls')),
)
所以我不完全确定问题出在哪里,感谢所有帮助。
非常感谢,我。