django-urls

How do I set urlpatterns based on domain name or TLD, in Django?

∥☆過路亽.° 提交于 2019-11-27 18:54:17
How do I set urlpatterns based on domain name or TLD, in Django? For some links, Amazon shows url in native language based on its website tld. http://www.amazon.de/bücher-buch-literatur/ ( de : books => bücher ) http://www.amazon.fr/Nouveautés-paraître-Livres/ ( fr : books => Livres ) http://www.amazon.co.jp/和書-ユーズドブッ-英語学習/ ( jp : books => 和書 ) ( the links are incomplete and just show as samples. ) Is it possible to get host name in urls.py? (request object is not available in urls.py) or maybe in process_request of middleware and use it in urls.py(how???) Any alternate suggestions how to

add request.GET variable using django.shortcuts.redirect

时光怂恿深爱的人放手 提交于 2019-11-27 18:18:52
Is possible to add GET variables in a redirect ? (Without having to modifiy my urls.py) If I do redirect('url-name', x) I get HttpResponseRedirect('/my_long_url/%s/', x) I don't have complains using HttpResponseRedirect('/my_long_url/%s/?q=something', x) instead, but just wondering... Is possible to add GET variables in a redirect ? (Without having to modifiy my urls.py) I don't know of any way to do this without modifying the urls.py . I don't have complains using HttpResponseRedirect('/my_long_url/%s/?q=something', x) instead, but just wondering... You might want to write a thin wrapper to

Making a Regex Django URL Token Optional

偶尔善良 提交于 2019-11-27 17:30:34
You have a URL which accepts a first_name and last_name in Django: ('^(?P<first_name>[a-zA-Z]+)/(?P<last_name>[a-zA-Z]+)/$','some_method'), How would you include the OPTIONAL URL token of title , without creating any new lines. What I mean by this is, in an ideal scenario: #A regex constant OP_REGEX = r'THIS IS OPTIONAL<title>[a-z]' #Ideal URL ('^(?P<first_name>[a-zA-Z]+)/(?P<last_name>[a-zA-Z]+)/OP_REGEX/$','some_method'), Is this possible without creating a new line i.e. ('^(?P<first_name>[a-zA-Z]+)/(?P<last_name>[a-zA-Z]+)/(?P<title>[a-zA-Z]+)/$','some_method'), ('^(?P<first_name>[a-zA-Z]+)

How to get the current url name using Django?

自作多情 提交于 2019-11-27 17:25:44
I have to build an url dynamically according to the current url. Using the {% url %} tag is the easiest way to do it, but I need the current url name to generate the new one dynamically. How can I get the url name attached to the urlconf that leads to the current view? EDIT : I know I can manually handcraft the url using get_absolute_url but I'd rather avoid it since it's part of a lecture and I would like to demonstrate only one way to build urls. The students know how to use {% url %} . They are know facing a problem when they have to generate a more complete url based on the current one.

Django's HttpResponseRedirect seems to strip off my subdomain?

旧城冷巷雨未停 提交于 2019-11-27 17:03:36
问题 Whenever my django site calls "HttpResponseRedirect" in a view object to redirect to another url it strips off the sub-domain and goes back to the main site. I'm working off of the SVN branch of Django. Here is the example: #Request comes in as https://sub1.mydomain.com def view(request): return HttpResponseRedirect("/test_url") #The browser will actually get redirected to https://mydomain.com/test_url Is there a reason this is done? Should I have to redirect to the full path including the

Getting Django admin url for an object

半世苍凉 提交于 2019-11-27 16:37:33
Before Django 1.0 there was an easy way to get the admin url of an object, and I had written a small filter that I'd use like this: <a href="{{ object|admin_url }}" .... > ... </a> Basically I was using the url reverse function with the view name being 'django.contrib.admin.views.main.change_stage' reverse( 'django.contrib.admin.views.main.change_stage', args=[app_label, model_name, object_id] ) to get the url. As you might have guessed, I'm trying to update to the latest version of Django, and this is one of the obstacles I came across, that method for getting the admin url doesn't work

Recursive URL Patterns CMS Style

≡放荡痞女 提交于 2019-11-27 16:25:43
问题 Whenever I learn a new language/framework, I always make a content management system... I'm learning Python & Django and I'm stuck with making a URL pattern that will pick the right page. For example, for a single-level URL pattern, I have: url(r'^(?P<segment>[-\w]+)/$', views.page_by_slug, name='pg_slug'), Which works great for urls like: http://localhost:8000/page/ Now, I'm not sure if I can get Django's URL system to bring back a list of slugs ala: http://localhost:8000/parent/child

url template tag in django template

你说的曾经没有我的故事 提交于 2019-11-27 14:11:09
问题 I was trying to use the url template tag in django, but no lucky, I defined my urls.py like this urlpatterns = patterns('', url(r'^analyse/$', views.home, name="home"), url(r'^analyse/index.html', views.index, name="index"), url(r'^analyse/setup.html', views.setup, name="setup"), url(r'^analyse/show.html', views.show, name="show"), url(r'^analyse/generate.html', views.generate, name="generate"), I defined the url pattern in my view like this {% url 'show'%} then I got this error message

Passing variable urlname to url tag in django template

余生长醉 提交于 2019-11-27 13:45:03
问题 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 sitechangeobject.urlname as a name (which is quite right, it doesn't exist). Is there any way to make it look inside that variable? There are other ways to solve this problem

How to get current_app for using with reverse in multi-deployable reusable Django application?

眉间皱痕 提交于 2019-11-27 11:48:45
问题 I'm writing reusable app. And I want to deploy it several times. Here is urls.py: urlpatterns = patterns('', (r'^carphotos/', include('webui.photos.urls', app_name='car-photos') ), (r'^userphotos/', include('webui.photos.urls', app_name='profile-photos') ),) and photos/urls.py: urlpatterns = patterns('webui.photos.views', url(r'^$', album_list, name="album-list" ) url(r'^newalbum/$', album_page, {'create': True}, name="album-create"),) On the album_list view I want to show url for creating