django-urls

Regular expression that uses an "OR" conditional

I could use some help writing a regular expression. In my Django application, users can hit the following URL: http://www.example.com/A1/B2/C3 I'd like to create a regular expression that allows accepts any of the following as a valid URL: http://www.example.com/A1 http://www.example.com/A1/B2 http://www.example.com/A1/B2/C3 I...

How does one put a link / url to the web-site's home page in Django?

In Django templates, is there a variable in the context (e.g. {{ BASE_URL }}, {{ ROOT_URL }}, or {{ MEDIA_URL }} that one can use to link to the "home" url of a project? I.e. if Django is running in the root of a project, the variable (let's call it R) {{ R }} in a template would be "/". If the root url is a sub-folder "http://host/X/" ...

Default parameters to actions with Django

Is there a way to have a default parameter passed to a action in the case where the regex didnt match anything using django? urlpatterns = patterns('',(r'^test/(?P<name>.*)?$','myview.displayName')) #myview.py def displayName(request,name): # write name to response or something I have tried setting the third parameter in the u...

Django: Arbitrary number of unnamed urls.py parameters

I have a Django model with a large number of fields and 20000+ table rows. To facilitate human readable URLs and the ability to break down the large list into arbitrary sublists, I would like to have a URL that looks like this: /browse/<name1>/<value1>/<name2>/<value2>/ .... etc .... where 'name' maps to a model attribute and 'value'...

How does one add default (hidden) values to form templates in Django?

Given a Django.db models class: class P(models.Model): type = models.ForeignKey(Type) # Type is another models.Model class name = models.CharField() where one wishes to create a new P with a specified type, i.e. how does one make "type" to be a default, hidden field (from the user), where type is given likeso: http://x.y/P/new?...

What is the regular expression for the "root" of a website in django?

I'm using django and when users go to www.website.com/ I want to point them to the index view. Right now I'm doing this: (r'^$', 'ideas.idea.views.index'), However, it's not working. I'm assuming my regular expression is wrong. Can anyone help me out? I've looked at python regular expressions but they didn't help me. ...

Django problem of resolving special characters in url

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/tag...

What's the best way to map the main urls in a django project?

I've got a django project that contain some apps. The main urls.py includes the urls.py from the apps I've enabled, and all is good. Now I want to configure the project so that when you go to http://testsite/, you'll get the same page that you get when you go to http://testsite/app/. I can do this by duplicating the corresponding line...

how to pass id from url to post_save_redirect in urls.py

Hi! I have several objects in the database. Url to edit an object using the generic view looks like site.com/cases/edit/123/ where 123 is an id of the particular object. Consider the cases/url.py contents: url(r'edit/(?P<object_id>\d{1,5})/$', update_object, { ... 'post_save_redirect': ???}, name = 'cases_edit'), where update_object i...

My Django URLs not picking up dashes

Im trying to work out a url that will match domain.com\about-us\ & domain.com\home\ I have a url regex: ^(?P<page>\w+)/$ but it won't match the url with the - in it. I've tried ^(?P<page>\.)/$ ^(?P<page>\*)/$ but nothing seems to work. ...

How can I pass some information to a view without including it in the URL (django newbie)

I'm working on a little django app for reserving prints of paintings. Customers go to this ordering page, fill out some information (name, email, dedication, etc), pick the print number they want to reserve, and click order. On clicking, I have my django code storing all the customer information in a new OrderInfo object, and it call...

How can I make sure that the urls work the same in built-in web-server and Apache

The situation is: I have Apache with mod_python on windows xp and my django project is not in the document root. The Django project location is defined with the tag. The django.root ist also defined there. All the urls work fine in the built-in server but unfortunately not in Apache. In some urls, especially the ones not pointing to the...

Django named urls, generic views?

So, here is one of my urls.py urlpatterns = patterns('items.views', url(r'^(?P<item_id>[\d+])/$', 'view_listing', name="item_view"), ) And in my template, I can do this: <a href="{% url item_view 1 %}">here</a> and I'll get a link to the right page. Everything works great! But, here is another one urlpatterns = patterns('django....

How to redirect a http request with apache / django

Hey everyone, I've made a simple site in Django. The urls I use are http::/www.example.com/nl/ and http://www.example.com/fr/. My Django urls.py has the following line: (r'^(?Pnl|fr)/', 'example.views.index'), In example.views.index I check the language parameter. If it's 'nl' I show a template. If it's 'fr', I show a different templ...

Specifying different template names in Django generic views

Hi, I have the code in my urls.py for my generic views; infodict = { 'queryset': Post.objects.all(), 'date_field': 'date', 'template_name': 'index.html', 'template_object_name': 'latest_post_list', } urlpatterns += patterns('django.views.generic.date_based', (r'^gindex/$', 'archive_index', infodict), ) So going to the address /gindex...

Reverse Not Found: Sending Request Context in from templates

N.B This question has been significantly edited before the first answer was given. Hi, I'm fairly new to django, so apologies if I'm missing something obvious. I've got a urls.py file that looks like this: urlpatterns = patterns( '', (r'^$', 'faros.lantern.views.home_page'), (r'^login/$', 'django.contrib.auth.views.login'...

Auto GET to argument of view

some_view?param1=10&param2=20 def some_view(request, param1, param2): Is such possible in Django? ...

Django -- ForeignKey() uses different column than the row ID?

Hi, I have an application called Location. Location has Country, State, City, Big_City_Nearby, Longitude, latitude. I have an application for an item for sell. Item has Title, Link, Description, Price & Location which is a ForeignKey(). Now, if someone wants to see all items for sell in the US, they click on a link (let say http://ex...

Django URLs - How to pass in multiple caterories via the clean URL without the need for ?

Hi, I want to stay way from GET params. Don't want to use POST and I have at least two different categories to build the URL for. The visitors are first asked to choose a location wich can be one of, for example: http://foo.com/United-States/ || http://foo.com/United-States/California/ || http://foo.com/United-States/California/San-...

No reverse error in Google App Engine Django patch?

I am using Google App Engine patch Django. When I try to go to the admin site, http://127.0.0.1:8080/admin/ , I keep getting this error: TemplateSyntaxError at /admin/ Caught an exception while rendering: Reverse for 'settings.django.contrib.auth.views.logout' with arguments '()' and keyword arguments '{}' not found. I...