django-urls

Does Django cache url regex patterns somehow?

I'm a Django newbie who needs help: Even though I change some urls in my urls.py I keep on getting the same error message from Django. Here is the relevant line from my settings.py: ROOT_URLCONF = 'mydjango.urls' Here is my urls.py: from django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: from dja...

Django urls on json request

When making a django request through json as, var info=id + "##" +name+"##" $.post("/supervise/activity/" + info ,[] , function Handler(data,arr) { } In urls.py (r'^activity/(?P<info>\d+)/$, 'activity'), In views, def activity(request,info): print info The request does not go through.info is a string.How can th...

URL redirection if wrong url

I have this method in my book model: def get_absolute_url(self): return "/book/%s/%s/%i/%i/" % ( self.book_title, self.book_editor, self.book_pages, self.id) So the urls of each book are like this: example.com/book/the-bible/gesu-crist/938/12/ I want that if there is an error in the url, then I get redirected to the rea...

Error URL redirection

urls.py: url(r'^book/(?P<booktitle>[\w\._-]+)/(?P<bookeditor>[\w\._-]+)/(?P<bookpages>[\w\._-]+)/(?P<bookid>[\d\._-]+)/$', 'book.views.book', name="book"), views.py: def book(request, booktitle, bookeditor, bookpages, bookid, template_name="book.html"): book = get_object_or_404(book, pk=bookid) if booktitle != book.book_t...

ModelMultipleChoiceField and reverse()

I have a form containing a ModelMultipleChoiceField. Is it possible to come up with a url mapping that will capture a varying number of parameters from said ModelMultipleChoiceField? I find myself doing a reverse() call in the view passing the arguments of the form submission and realized that I don't know how to represent, in the url...

Django Error: NameError name 'current_datetime' is not defined

I'm working through the book "The Definitive Guide to Django" and am stuck on a piece of code. This is the code in my settings.py: ROOT_URLCONF = 'mysite.urls' I have the following code in my urls.py from django.conf.urls.defaults import * from mysite.views import hello, my_homepage_view urlpatterns = patterns('', ('^hello/$', hell...

Django: Site-Wide URL Prefix

I've built a Django site that will live at the root when it's live. Right now it's functioning perfectly at the IP address. For testing purposes, the client has pointed a proxy url at it, but the url has /folder/path in it, so none of the URL patterns match. I put (/folder/path)? into all the url patterns so they now respond, but all of ...

Django URL resolving infrastructure stops working

We recently launched a new Django-powered website, and we are experiencing the oddest bug: The site is running under Apache with mod_fastcgi. Everything works fine for a while, and then the URL tag and reverse() functionality stops working. Instead of returning the expected URL, they return "". We haven't noticed anything in Apache's ...

Django site_media relative url problem

Hello, in my settings.py I have the following: PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) MEDIA_ROOT = os.path.join(PROJECT_DIR,'templates') MEDIA_URL = '/templates/' In urls.py I have (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), And my base.html has the f...

Django URL Conf Returns Incorrect "Current URL"

I have a django app that is mostly done, and the URLs work perfectly when I run it with the manage.py runserver command. However, I've recently tried to get it running via lighttpd, and many links have stopped working. For example: http://mysite.com/races/32 should work, but instead throws this error message. Page not found (404) Reque...

Login URL using authentication information in Django

I'm working on a platform for online labs registration for my university. Login View [project views.py] from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib import auth def index(request): return render_to...

How can you dispatch on request method in Django URLpatterns?

It's clear how to create a URLPattern which dispatches from a URL regex: (r'^books/$', books), where books can further dispatch on request method: def books(request): if request.method == 'POST': ... else: ... I'd like to know if there is an idiomatic way to include the request method inside the URLPattern, ...

Django localeURL when WSGIScriptAlias is /PREFIX

Good morning everyone, Introduction I Got a question about localeURL usage. Everything works great for me with url like this : http://www.mysite.com/ If I type http://www.mysite.com/ in adress bar, it turns correctly in http://www.mysite.com/en/ for example. If I use the view change_locale, it's also all right (ie change www.mysite...

Django - problem with {% url facebook_xd_receiver %}

I'm using {% url facebook_xd_receiver %} in one of my HTML files. This works just fine when I run my project using the command python manage.py runserver But the same project stops running and gives me a "TemplateSyntaxError" at the line {% url facebook_xd_receiver %} Can anyone please tell me what could be the difference betwe...

Passing variable urlname to url tag in django template

Hi All, What I'd like to do (for a recent changes 'widget' - not a django widget in this case) is pass a urlname into my template as a variable, then use it like so: {% url sitechangeobject.urlname %} Where urlname is a string containing a valid name for a url. Is this possible? The template keeps breaking saying it can't find sitechan...

Broken Link On Django Admin Interface

I'm currently reading Practical Django Projects and in the Django admin interface there is an option to "View on site" when entering information. But after finishing chapter 5 of the book I started to tinker with the admin interface and found that clicking this link with my categories app doesn't work as it isn't appending weblog to the...

Django query to get next previous item by date in category...

Hello. First time poster to Stack Overflow... I suspect my answer lies in this solution: http://stackoverflow.com/questions/2074514/django-query-that-get-most-recent-objects-from-different-categories but I am having trouble 'getting' Django's annotate() functionality. I've gotten this far: previous = Item.objects.filter(date_added...

Django url parsing -pass raw string

Hello, I'm trying to pass a 'string' argument to a view with a url. The urls.py goes ('^add/(?P<string>\w+)', add ), I'm having problems with strings including punctuation, newlines, spaces and so on. I think I have to change the \w+ into something else. Basically the string will be something copied by the user from a text of his cho...

Django url configuration for DRYness

Hi All, Most views in my project accept an optional username parameter and if exists, filter the querysets passed to the templates for that user. So, for example: the index view handles both the following url patterns: '^$' # general index page '^(?P<username>[-\w]+)/$' # index page for the user '^photos/$' # photo index page '^(?P<u...

Django - limiting url access to superusers

In my urlconf, i have: url(r'^sssssh/(.*)', staff_only_app.site.root), What I'd like to do is limiting any access to this application to superusers. I tried this: url(r'^sssssh/(.*)', user_passes_test(staff_only_app.site.root, lambda u: u.is_superuser)), But it complains that decorate takes exactly 1 argument, and I gave two. I'...