django-urls

Django - limiting url access to superusers

拥有回忆 提交于 2019-12-11 06:26:36
问题 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'm thinking about currying the decorator via functools.partial, but thought I may be missing some more obvious solution. 回答1: Very late reply!... I think it's just a

In Django, how do I write a url.py where users/self/ is the same as users/<pk>/, where <pk> is your logged in user pk?

老子叫甜甜 提交于 2019-12-11 05:19:43
问题 I am trying to write a url.py where I have a simple view for users urlpatterns = patterns( 'doors.view', url( r'^users/$' , 'users_list' , name = 'users_list' ), url( r'^users/(?P<pk>\d+)/$', 'users_detail', name = 'users_detail' ), url( r'^users/self/$' , # do some sort of redirect here ), ) The problem with the redirect is I don't know the pk of the logged in user in url.py . In view.py , I would obviously do a @login_required to be able to access users/self/ . Maybe I am doing this wrong

Django: no reverse url match with multiple parameters

雨燕双飞 提交于 2019-12-11 05:15:27
问题 My URLs need to capture the following: domain/forum-name/ domain/forum-name/topic-name I have the following URL definitions: url(r'^$', views.index_forums, name='index_forums'), url(r'^(?P<forum_name>[-\w]+)/(?P<topic_name>[-\w]+)/$', views.show_topic, name='show_topic'), url(r'^(?P<forum_name>[-\w]+)/$', views.index_topics, name='index_topics'), When I hit a URL like domain/name-of-forum, I generate URLs in the HTML like so: {% url 'board:show_topic' forum_name|lower topic.title|lower %}

django Removing hardcoded URLs in templates

岁酱吖の 提交于 2019-12-11 05:09:13
问题 I know that in a template file I can include this code which will return a list of links {% for q in all %} <ul> <li><a href={% url 'detail' q.id %}>{{ q.question_text }}</a></li> </ul> {% endfor %} Now django will search for the name 'detail' in the urls.py file of my app directory and it will automatically give the value of q.id to that argument. But what if I have a url that contains more than 1 variable. So here I can only give one argument i.e, q.id . But what if I want to give more than

Django Context Processor Trouble

早过忘川 提交于 2019-12-11 04:48:38
问题 So I am just starting out on learning Django, and I'm attempting to complete one of the sample applications from the book. I'm getting stuck now on creating DRY URL's. More specifically, I cannot get my context processor to work. I create my context processor as so: from django.conf import settings #from mysite.settings import ROOT_URL def root_url_processor(request): return {'ROOT_URL': settings.ROOT_URL} and I placed this file in my app, specifically, mysite/photogallery/context_processors

Django - Dynamic view for url

杀马特。学长 韩版系。学妹 提交于 2019-12-11 03:44:32
问题 I want to load a particular view depending on the url, for example: url(r'^channel/(?P<channel>\d+)/$', ---, name='channel_render'), Depending on the channel passed into the url, I want to load a specific view file. I tried doing this: def configure_view(channel): print channel urlpatterns = patterns('', url(r'^channel/(?P<channel>\d+)/$', configure_view(channel), name='channel_render'), But obviously the channel argument is not getting passed in. Is there any way to do this? The only other

NoReverseMatch: Reverse for 'complete' with arguments '(1,)' not found. 1 pattern(s) tried: ['complete/<todo_id>']

白昼怎懂夜的黑 提交于 2019-12-11 02:34:31
问题 urls.py from django.conf.urls import url from . import views urlpatterns = [ url('', views.index, name= 'index'), url('add', views.addTodo, name ='add'), url('complete/<todo_id>', views.completeTodo, name='complete'), url('deletecomplete', views.deleteCompleted, name='deletecomplete'), url('deleteall', views.deleteAll, name='deleteall') ] views.py( portion of a program) def completeTodo(request, todo_id): todo = Todo.objects.get(pk=todo_id) todo.complete = True todo.save() return redirect(

ERROR: ' No module named 'django.core.urlresolvers'

心不动则不痛 提交于 2019-12-11 00:54:37
问题 I am trying to create web services using the Django REST Framework. While running the server, when I try to access the admin page, I get the following error: Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': No module named 'django.core.urlresolvers' Note: I have added the rest_framework in the settings. 回答1: Use this. from django.urls import reverse Django 1.10 the module django.core.urlresolvers deprecated. Please use

Multiple url dispatches with Regex

徘徊边缘 提交于 2019-12-11 00:27:42
问题 I have a two URL dispatches. One that catches words on http://domain.com/thisword , while the second dispatch is a sitemap on http://domain.com/sitemap.xml . The current code which does not work correct is: urlpatterns = patterns('', url(ur'(?P<search_word>[ÆØÅæøåa-zA-Z]*)/?$', 'website.views.index_view', name='website_index'), url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), ) So basically the first dispatch catches everything, including sitemap.xml .

Decorating all django admin views (1.4+)

北慕城南 提交于 2019-12-10 17:28:31
问题 There used to be a neat trick for Django versions prior to 1.4 to decorate all views within the admin: urlpatterns = patterns('', (r'^admin/(.*)', my_decorator(lambda *args: admin.site.root(*args))), ) This no longer works as root is deprecated. I have found some alternatives, but they seem pretty verbose compared to what I had. Is there still a hook to do this? 回答1: Decorate every view in a url tree http://djangosnippets.org/snippets/2607/ 来源: https://stackoverflow.com/questions/14537829