django url 正则表达式不匹配
使用 Django 1.3 与开发服务器
我尝试连接: http://127.0.0.1:8000/lang/en
答案是:
使用中定义的 URLconf pruebas.urls,Django 尝试了这些 URL 模式,按此顺序:
- ^管理员/
- ^correo/$
- ^登录/$
- ^lang/(?P\w+)/$
- ^site_static/(?P.*)$
当前 URL 与以下任何一个都不匹配 这些。
这是我的“urls.py”:
from pruebas import settings
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'pruebas.views.home', name='home'),
# url(r'^pruebas/', include('pruebas.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)),
(r'^correo/$', 'mailclient.views.index'),
(r'^login/$', 'kusers.views.klogin'),
# Language change
(r'^lang/(?P<lang_code>\w+)/$', 'kusers.views.lang'),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),)
我认为该行:
(r'^lang/(?P\w+)/$', 'kusers.views.lang')
将与“http://127.0 .0.1:8000/lang/en”,但看来我错了。
提前致谢
kuusers/views.py 中的代码是:
def lang(request, lang_code):
request.session['django_language'] = lang_code
return HttpResponseRedirect( "/" )
已解决。
问题不在于 urls.py 配置。问题在于“kuser”应用程序文件夹结构。
谢谢
Using Django 1.3 with development server
I try to connect with: http://127.0.0.1:8000/lang/en
The answer is:
Using the URLconf defined in
pruebas.urls, Django tried these URL
patterns, in this order:
- ^admin/
- ^correo/$
- ^login/$
- ^lang/(?P\w+)/$
- ^site_static/(?P.*)$
The current URL, , didn't match any of
these.
And this is my "urls.py":
from pruebas import settings
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
def lang(request, lang_code):
request.session['django_language'] = lang_code
return HttpResponseRedirect( "/" )
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
, 'pruebas.views.home', name='home'),
# url(r'^pruebas/', include('pruebas.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)),
(r'^correo/
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
, 'mailclient.views.index'),
(r'^login/
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
, 'kusers.views.klogin'),
# Language change
(r'^lang/(?P<lang_code>\w+)/
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
, 'kusers.views.lang'),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_static/(?P<path>.*)
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
, 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),)
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在网址上添加尾部斜杠,它将起作用,如下所示:
http://127.0.0.1: 8000/郎/en/
If you put a trailing slash on the url it will work, as in:
http://127.0.0.1:8000/lang/en/