urlconf

django - regex for optional url parameters

核能气质少年 提交于 2019-12-03 13:13:25
问题 I have a view in django that can accept a number of different filter parameters, but they are all optional. If I have 6 optional filters, do I really have to write urls for every combination of the 6 or is there a way to define what parts of the url are optional? To give you an example with just 2 filters, I could have all of these url possibilities: /<city>/<state>/ /<city>/<state>/radius/<miles>/ /<city>/<state>/company/<company-name>/ /<city>/<state>/radius/<miles>/company/<company-name>/

Registering API in apps

孤街醉人 提交于 2019-12-03 09:18:55
问题 With django-rest-framework I'm using the DefaultRouter I want to provide APIs to several apps, so my question is can I do this in a django manner and put my router registrations in each app URLconf and have them appear either as one aggregate api or ideally in a namespaced way. In other words if app1 contains modelA and modelB , while app2 contains modelC : can I declare 2 routers that appear at mysite/app1/api and mysite/app2/api , or can I have a single api at mysite/api which lists all

Including a querystring in a django.core.urlresolvers reverse() call

一世执手 提交于 2019-12-03 05:30:16
问题 I'm trying to reverse a named URL and include a querystring in it. Basically, I've modified the login function, and I want to send ?next= in it. Here's what I'm doing now: reverse(name) + "?next=" + reverse(redirect) Here's what I'd like to do: reverse(name, kwargs = { 'next':reverse(redirect) } ) My URL for the login page (just as an example) looks like this: url(r'^login/', custom_login, name = 'login'), So how do I modify this whole thing (or call it) to include the next without having to

Including a querystring in a django.core.urlresolvers reverse() call

冷暖自知 提交于 2019-12-02 19:57:01
I'm trying to reverse a named URL and include a querystring in it. Basically, I've modified the login function, and I want to send ?next= in it. Here's what I'm doing now: reverse(name) + "?next=" + reverse(redirect) Here's what I'd like to do: reverse(name, kwargs = { 'next':reverse(redirect) } ) My URL for the login page (just as an example) looks like this: url(r'^login/', custom_login, name = 'login'), So how do I modify this whole thing (or call it) to include the next without having to concatenate it? It feels like an iffy solution at best. Yuji 'Tomita' Tomita You can't capture GET

Django: How to access URL regex parameters inside a middleware class?

北城以北 提交于 2019-11-29 13:53:59
I am working on a Django project on Google App Engine. I have a URL like: http://localhost:8080/[company]/projects/project Note that [company] is a URL parameter defined in my urls.py like: (r'(^[a-zA-Z0-9-_.]*)/projects/project/(\d*)', 'projects.views.project_form'), I want to get the value of [company] from a middleware where I will set the GAE datastore namespace to the [company] value. Is it possible to get the [company] parameter from the request object passed in the process_request method of middleware class? If you are using the process_view middleware, you will have access to the views

Django Url, Slug for Detail Page

a 夏天 提交于 2019-11-28 20:50:41
I'm having trouble configuring my url to display a detail view. Clicking on this link: <a href='{% url blog_detail blog.slug %}'>{{ blog.name }}</a> shows blog.html , when I thought it would show blog-detail.html . There are no errors and the browser bar says: example.com/blog/the-slug , yet still displays the html from blog.html , not blog-detail.html . Any ideas why? Thanks for your ideas. url: url(r'^blog/', 'myapp.views.blog', name='blog'), url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views.blog_detail', name='blog_detail'), views: def blog(request): blog_list = Blog.objects.all() return render

Django, name parameter in urlpatterns

北慕城南 提交于 2019-11-28 17:46:24
I'm following a tutorial where my urlpatterns are: urlpatterns = patterns('', url(r'^passwords/$', PasswordListView.as_view(), name='passwords_api_root'), url(r'^passwords/(?P<id>[0-9]+)$', PasswordInstanceView.as_view(), name='passwords_api_instance'), ...other urls here..., ) The PasswordListView and PasswordInstanceView are supposed to be class based views. I could not figure out the meaning of the name parameter. Is it a default parameter passed to the view? No. It is just that django gives you the option to name your views in case you need to refer to them from your code, or your

Django: How to access URL regex parameters inside a middleware class?

爷,独闯天下 提交于 2019-11-28 07:48:10
问题 I am working on a Django project on Google App Engine. I have a URL like: http://localhost:8080/[company]/projects/project Note that [company] is a URL parameter defined in my urls.py like: (r'(^[a-zA-Z0-9-_.]*)/projects/project/(\d*)', 'projects.views.project_form'), I want to get the value of [company] from a middleware where I will set the GAE datastore namespace to the [company] value. Is it possible to get the [company] parameter from the request object passed in the process_request

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.

How to get the current url name using Django?

我是研究僧i 提交于 2019-11-26 18:58:08
问题 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 %} .