2

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'^$', '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}),)

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

1
  • What does your lang view code look like? Commented May 3, 2011 at 16:31

1 Answer 1

3

If you put a trailing slash on the url it will work, as in:

http://127.0.0.1:8000/lang/en/

Sign up to request clarification or add additional context in comments.

1 Comment

The $ symbol at the end means that the expression must end with the given expression. without the $, /lang/en/blah would match too. Also, try add APPEND_SLASH = True in your settings.py as described in the docs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.