django-urls

Django - how can I get permalink to work with “throwaway” slug

对着背影说爱祢 提交于 2019-12-03 17:10:39
I'm trying to add slugs to the url in my django app, much like SO does. Currently, I have pages that work just fine with a url like this: http://example.com/foo/123/ I'd like to add 'slugified' urls like so: http://example.com/foo/123/foo-name-here I can get it to work just fine, by simply modifying the urlconf and adding a throwaway value to the view function: #urls.py ulpatterns = patterns('project.app.views', url(r'^foo/(?P<foo_id>\d+)/(?P<name_slug>\w+)/$', 'foo_detail', name='foo_detail'), ) #views.py: def foo_detail(request, foo_id, name_slug): # stuff here, name slug is just discarded

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

不打扰是莪最后的温柔 提交于 2019-12-03 15:05:58
问题 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,

New url format in Django 1.9

心不动则不痛 提交于 2019-12-03 15:04:37
问题 I recently upgraded my Django project to version 1.9. When I try to run migrate , I am getting the following two errors: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got app.views.about). Pass the callable instead. django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead. Could someone please show me the proper syntax of how to do this? A brief

Getting 'str' object has no attribute 'get' in Django

我与影子孤独终老i 提交于 2019-12-03 14:33:40
问题 views.py def generate_xml(request, number): caller_id = 'x-x-x-x' resp = twilio.twiml.Response() with resp.dial(callerId=caller_id) as r: if number and re.search('[\d\(\)\- \+]+$', number): r.number(number) else: r.client('test') return str(resp) url.py url(r'^voice/(?P<number>\w+)$', 'django_calling.views.generate_xml', name='generating TwiML'), Whenever I am requesting http://127.0.0.1:8000/voice/number?id=98 getting following error: Request Method: GET Request URL: http://127.0.0.1:8000

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

社会主义新天地 提交于 2019-12-03 14:25:14
问题 This question already has answers here : Determine complete Django url configuration (9 answers) Closed 4 years ago . 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

Django problem of resolving special characters in url

一世执手 提交于 2019-12-03 13:39:51
We have a website made by Django. And there is no problem when access following url on local working environment: http://site/tags/c%23/ "c%23" is urlencode of "c#", that works fine locally. But after we deploy it on Bluehost hosting server (apache+fastcgi), this URL has been resolved to a new address like this: http://site/t/tags/c/ That's too weird. Probably it's not a Django's problem, but have something to do with Apache url's rewrite. If you have any idea or suggestion how to fix this please let me know. Thanks in advance. Here is the .htaccess file may be considered: AddHandler fcgid

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

放肆的年华 提交于 2019-12-03 13:34:23
问题 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? 回答1: I assume you mean you want to do URLs like this: /trance/ /trance/vocal-trance/ /trance/hard-trace/ /breaks/ /breaks

Django url debugger

南楼画角 提交于 2019-12-03 10:45:51
问题 I'm developing a django application and over time, the URLs have grown. I have a lot of them with me now and due to some change I made, one view started to malfunction. When I try to GET http://example.com/foo/edit_profile, it's supposed to execute a view certain view function X but it's executing Y instead. Somewhere the url routing is messing up and I can't figure it out. I used the django.core.urlresolvers.resolve method to try it from the shell and I can confirm that the URL is getting

Django - How to pass several arguments to the url template tag

折月煮酒 提交于 2019-12-03 09:47:51
In my urls.py I have: (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/section/(?P<slug>[-\w]+)/$', 'paper.views.issue_section_detail', {}, 'paper_issue_section_detail' ), and I'm trying to do this in a template: {% url paper_issue_section_detail issue.pub_date.year,issue.pub_date.month,issue.pub_date.day,section_li.slug %} but I get this error: TemplateSyntaxError Caught an exception while rendering: Reverse for 'paper_issue_section_detail' with arguments '(2010, 1, 22, u'business')' and keyword arguments '{}' not found. However, if I change the URL pattern to only require a single

How to display custom 404.html page in Django

ぃ、小莉子 提交于 2019-12-03 09:01:50
I want to display custom 404 error page when end user enters wrong url,I have tried but i am getting only Django default 404 page.I am using Python(2.7.5),Django(1.5.4) My Code urls.py from django.conf.urls import patterns, include, url from mysite import views handler404 = views.error404 urlpatterns = patterns('', url(r'^$', 'mysite.views.home', name='home'), ) views.py from django.http import HttpResponse from django.shortcuts import render from django.template import Context, loader def home(request): return HttpResponse("welcome to my world") def error404(request): template = loader.get