社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

求助:好像是django配置URLS的问题,但不知道哪里错了,麻烦各位高手指教

zzbwang • 9 年前 • 22923 次点击  

我按照Django官网的例子写了第一个view,mysite/polls/views.py文件内容:

from django.http import HttpResponse

def index(request):

    return HttpResponse("Hello world. You're at the polls index.")

mysite/urls.py文件内容:

from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

mysite/polls/urls.py文件内容

from django.conf.urls import patterns, url
from polls import views

urlpatterns = patterns('', 
    url(r'^$', views.index, name='index'), 
    )

运行server,并访问:http://localhost:8000/polls/

Page not found (404)
Request Method:     GET
Request URL:    http://localhost:8000/polls/

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

   1. ^admin/

The current URL, polls/, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

在django的URLpattern列表中居然没有^polls,不知道啥原因,麻烦各位高手指教。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/710
 
22923 次点击  
文章 [ 17 ]  |  最新文章 9 年前