我是 Django 新手,我对 Django URL 调度程序有一些问题。
我有“prometfire”项目和“主页”应用程序。
我的目标是将此路径连接到他们的视图功能:
127.0.0.1:8000 --> "主页视图"
127.0.0.1:8000/欢迎 --> "welcome_view"
“homepage_view”工作正常,但是当我转到 127.0.0.1:8000/welcome 时,我的结果与“homepage_view”中的结果相同,而不是“welcome_view”结果。
我错过了什么吗?
Django 1.5 Python 2.7
#urls.py in prometfire
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('homepage.urls')),
url(r'^welcome/', include('homepage.urls')),
url(r'^admin/', include(admin.site.urls)),
)
#urls.py in homepage app
from django.conf.urls import patterns, include, url
urlpatterns = patterns('homepage.views',
url(r'^$', 'homepage_view'),
url(r'^welcome/', 'welcome_view'),
)
#views.py in homepage app
from django.shortcuts import render_to_response
from django.http import HttpResponse
def homepage_view(request):
return render_to_response('homepage.html',
{'name': 'bob'}
)
def welcome_view(request):
return HttpResponse('Welcome')