django url 正则表达式不匹配

发布于 2024-11-04 10:09:23 字数 1802 浏览 4 评论 0原文

使用 Django 1.3 与开发服务器

我尝试连接: http://127.0.0.1:8000/lang/en

答案是:

使用中定义的 URLconf pruebas.urls,Django 尝试了这些 URL 模式,按此顺序:

  1. ^管理员/
  2. ^correo/$
  3. ^登录/$
  4. ^lang/(?P\w+)/$
  5. ^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:

  1. ^admin/
  2. ^correo/$
  3. ^login/$
  4. ^lang/(?P\w+)/$
  5. ^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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2024-11-11 10:09:23

如果您在网址上添加尾部斜杠,它将起作用,如下所示:

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文