编程语言
首页 > 编程语言> > python – Django以某种方式缓存url正则表达式模式吗?

python – Django以某种方式缓存url正则表达式模式吗?

作者:互联网

我是一个需要帮助的Django新手:即使我在urls.py中更改了一些网址,我也会继续从Django获取相同的错误消息.这是我的settings.py中的相关行:

ROOT_URLCONF = 'mydjango.urls'

这是我的urls.py:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^mydjango/', include('mydjango.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
    # to INSTALLED_APPS to enable admin documentation:
    #(r'^admin/doc/', include(django.contrib.admindocs.urls)),

    # (r'^polls/', include('mydjango.polls.urls')),
    (r'^$', 'mydjango.polls.views.homepage'),
    (r'^polls/$', 'mydjango.polls.views.index'),
    (r'^polls/(?P<poll_id>\d+)/$', 'mydjango.polls.views.detail'),
    (r'^polls/(?P<poll_id>\d+)/results/$', 'mydjango.polls.views.results'),
    (r'^polls/(?P<poll_id>\d+)/vote/$', 'mydjango.polls.views.vote'),
    (r'^polls/randomTest1/', 'mydjango.polls.views.randomTest1'),
    (r'^admin/', include(admin.site.urls)),
)

所以我希望每当我访问http://mydjango.yafz.org/polls/randomTest1/时mydjango.polls.views.randomTest1函数都应该运行,因为在我的polls / views.py中我有相关的功能:

def randomTest1(request):
    # mainText = request.POST['mainText']
    return HttpResponse("Default random test")

但是,我继续收到以下错误消息:

Page not found (404)
Request Method:     GET
Request URL:    http://mydjango.yafz.org/polls/randomTest1

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

   1. ^$
   2. ^polls/$
   3. ^polls/(?P<poll_id>\d+)/$
   4. ^polls/(?P<poll_id>\d+)/results/$
   5. ^polls/(?P<poll_id>\d+)/vote/$
   6. ^admin/
   7. ^polls/randomTest/$

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

我很惊讶,因为我一次又一次地检查urls.py并且没有

 ^polls/randomTest/$

在它,但有

 ^polls/randomTest1/'

似乎Django以某种方式存储了urls.py的先前内容,我只是不知道如何使我的最新更改生效.

有任何想法吗?当我尝试加载该页面时,为什么我继续看到一些旧版本的正则表达式,即使我更改了我的urls.py?

解决方法:

由于性能原因,Django在启动时编译URL正则表达式 – 重新启动服务器,您应该看到新URL正常工作.

标签:python,django,django-urls
来源: https://codeday.me/bug/20190526/1159015.html