Created
December 6, 2009 01:30
-
-
Save mikexstudios/249968 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The below code is running django 1.1.1; There is one app called 'foo' in the project. | |
Essentially what I'm doing is having a "catch-all" in the project urls.py that includes | |
foo's urls.py. So any url of the form: /\w+/hello/ should trigger foo.views.hello. That | |
works fine. | |
The problem is that reverse('hello'), where 'hello' is the named url, *always* gives | |
/x/hello/ no matter what value \w+ is. Is this normal behavior? | |
In other words, I expect that if I access: /test/hello/ that reverse('hello') gives | |
/test/hello/. However, it gives /x/hello/. | |
Directory structure and relevant sources below: | |
(env)mXs-MBP:url_test mikeh$ ls | |
__init__.py foo settings.py urls.pyc | |
__init__.pyc manage.py settings.pyc | |
env requirements.txt urls.py | |
(env)mXs-MBP:url_test mikeh$ cat 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'^url_test/', include('url_test.foo.urls')), | |
(r'^\w+/', include('url_test.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')), | |
# Uncomment the next line to enable the admin: | |
# (r'^admin/', include(admin.site.urls)), | |
) | |
(env)mXs-MBP:url_test mikeh$ cd foo | |
(env)mXs-MBP:foo mikeh$ ls | |
__init__.py models.py urls.py views.py | |
__init__.pyc tests.py urls.pyc views.pyc | |
(env)mXs-MBP:foo mikeh$ cat urls.py | |
from django.conf.urls.defaults import * | |
import foo.views | |
# Uncomment the next two lines to enable the admin: | |
# from django.contrib import admin | |
# admin.autodiscover() | |
urlpatterns = patterns('', | |
# Example: | |
# (r'^url_test/', include('url_test.foo.urls')), | |
url(r'^hello/', foo.views.hello, name='hello'), | |
# 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')), | |
# Uncomment the next line to enable the admin: | |
# (r'^admin/', include(admin.site.urls)), | |
) | |
(env)mXs-MBP:foo mikeh$ cat views.py | |
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseServerError | |
from django.core.urlresolvers import reverse | |
def hello(request): | |
url = reverse('hello') | |
return HttpResponse('This is the reversed url: '+url) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment