django-urls

Django and urls.py: How do I HttpResponseRedirect via a named url?

折月煮酒 提交于 2019-12-03 08:21:40
问题 I'm writing a member-based web application, and I need to be able to redirect the page after login. I want to use the named url from my urls.py script in my views.py file for the login application, but I can't for the life of me figure out what to do. What I have is this: def login(request): if request.session.has_key('user'): if request.session['user'] is not None: return HttpResponseRedirect('/path/to/page.html') What I want to accomplish is something like: def login(request): if request

How to use namespace urls with django in a reusuable app

旧街凉风 提交于 2019-12-03 06:50:23
问题 I have a django app, a forum app, that has templates with it. In those templates, there are urls that point to parts of the app. For instance the thread_list template has links to each thread like so: {% for thread in threads %} <a href="{% url forum_thread thread %}">{{thread.title}}</a> {% endfor %} The thing is, I don't really like calling my urls "forum_thread". I prefer just "thread" and using the namespace feature of django. "forum_thread" may be used somewhere else in the project

How to do reverse URL search in Django namespaced reusable application

这一生的挚爱 提交于 2019-12-03 04:15:05
问题 Consider that I include namespaced reusable application: urlpatterns = patterns('', # ella urls url('^ella/', include('ella.core.urls', namespace="ella")), ) Now, the Ella applications has urls like that: urlpatterns = patterns( '', url( r'^(?P<category>[a-z0-9-/]+)/$', category_detail, name="category_detail" ), # object detail url( r'^(?P<category>[a-z0-9-/]+)/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<content_type>[a-z0-9-]+)/(?P<slug>[a-z0-9-]+)/$', object_detail, name="object

Is there something similar to 'rake routes' in django? [duplicate]

半城伤御伤魂 提交于 2019-12-03 04:14:06
This question already has answers here : Determine complete Django url configuration (9 answers) In rails, on can show the active routes with rake ( http://guides.rubyonrails.org/routing.html ): $ rake routes users GET /users {:controller=>"users", :action=>"index"} formatted_users GET /users.:format {:controller=>"users", :action=>"index"} POST /users {:controller=>"users", :action=>"create"} POST /users.:format {:controller=>"users", :action=>"create"} Is there a similar tool/command for django showing the e.g. the URL pattern, the name of the pattern (if any) and the associated function in

Reverse Django generic view, post_save_redirect; error 'included urlconf doesnt have any patterns'

落花浮王杯 提交于 2019-12-03 03:58:49
I did see the other question titled 'how to use django reverse a generic view' and 'django named urls, generic views' however my question is a little different and I do not believe it is a dupe. Code: from django.views.generic import list_detail, create_update from django.core.urlresolvers import reverse from django.conf.urls.defaults import * partners_add = {'form_class': FooForm, 'post_save_redirect': reverse('foo-list'), } urlpatterns = patterns('', url(r'^foo/$', list_detail.object_list, foo_list, name='foo-list'), url(r'^foo/add/$', create_update.create_object, foo_add, name='foo-add'), )

How do you use Django URL namespaces?

99封情书 提交于 2019-12-03 03:38:12
问题 I'm trying to get the hang of Django URL namespaces. But I can't find any examples or documentation. Here is what I have tried. urls.py: from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^foo/', include('sub_urls', namespace='foo', app_name='foo')), (r'^bar/', include('sub_urls', namespace='bar', app_name='bar')), ) sub_urls.py: from django.conf.urls.defaults import patterns, url from views import view1 urlpatterns = patterns('views', url(r'^(?P<view_id>\d+)/$', view1,

Django-MPTT full path to child pages how to make?

那年仲夏 提交于 2019-12-03 03:30:00
I'm start using Django-MPTT app to get a tree-based approach on my Django-site pages. For ex. I have pages with sub pages: Trance: Vocal Trance(sub page) Hard Trance(sub page) Breaks: Atmo Breaks(sub page) Progressive Breaks(sub page) How can I get access to them from urls.py? What pattern will help? Do I need to store Full_path in model or it can be done via url pattern? craigds I assume you mean you want to do URLs like this: /trance/ /trance/vocal-trance/ /trance/hard-trace/ /breaks/ /breaks/atmo-breaks/ /breaks/progressive-breaks/ If so, it's probably best to store the url fragment in your

{% url %} gives me NoReverseMatch error while reverse() returns the url just fine. Why?

纵然是瞬间 提交于 2019-12-03 03:15:44
I don't know if this SO question is of the same problem that I am about to describe, but it does share the same symptoms. Unfortunately, it still remains unresolved as I am writing. So here is my problem. I am trying to add James Bennett's django-registration app to my django project. I have pretty much finished configuring it to my needs - custom templates and urls. Just when I thought everything was good to go. I got NoReverseMatch error from using {% url 'testing' item_id=123 %} (I also tried using the view name, myapp.views.test , instead but no luck) in one of the custom templates

How do I unit test django urls?

烈酒焚心 提交于 2019-12-03 01:50:55
问题 I have achieved 100% test coverage in my application everywhere except my urls.py . Do you have any recommendations for how I could write meaningful unit tests for my URLs? FWIW This question has arisen as I am experimenting with Test-Driven Development and want failing tests before I write code to fix them. 回答1: One way would be to reverse URL names and validate Example urlpatterns = [ url(r'^archive/(\d{4})/$', archive, name="archive"), url(r'^archive-summary/(\d{4})/$', archive, name=

Django URLS, how to map root to app?

冷暖自知 提交于 2019-12-03 01:28:50
问题 I am pretty new to django but experienced in Python and java web programming with different frameworks. I have made myself a nice little django app, but I cant seem to make it match www.mysite.com as opposed to www.mysite.com/myapp. I have defined urls and views in my urls.conf which is currently not decoupled from the app (don't mind that). urlpatterns = patterns('myapp.views', (r'^myapp/$', 'index'), (r'^myapp/(?P<some_id>\d+)/global_stats/$', 'global_stats'), (r'^myapp/(?P<some_id>\d+)