django-urls

Simulating a POST request in Django

戏子无情 提交于 2019-12-10 17:05:08
问题 Let's suppose I have the following url: /valid/django/app/path/?foo=bar&spam=eggs I can simulate a request to this URL in Django thusly: from django.shortcuts import render from django.core.urlresolvers import resolve def simulate(request, url=None, template_name="not_important.html"): if url: dv = resolve(url.split('?')[0]) return dv.func(request, *dv.args, **dv.kwargs) else: return render(request, template_name) However, I'd like to include the parameters to the included view, so that the

Does Django cache url regex patterns somehow?

橙三吉。 提交于 2019-12-10 15:56:28
问题 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 django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Example: # (r'^mydjango/', include('mydjango.foo.urls')), # Uncomment the admin/doc line

Django urls.py and views.py behaviour -

谁都会走 提交于 2019-12-10 11:41:45
问题 I'm currently experimenting with Django and creating apps following the tutorials on the official website. So my urls.py looks like: urlpatterns = patterns('', (r'^/$','ulogin.views.index'), #why doesn't this work? (r'^ucode/$', 'ulogin.views.index'), (r'^ucode/(\d+)/$', 'ulogin.views.index'), ) And my views.py looks like: def index(request): return HttpResponse("Hello, world. You're at the poll index.") def redirect_to_index(request): return HttpResponseRedirect('/ucode/') When I run the

Passing arguments to views in Django from constrained choices

送分小仙女□ 提交于 2019-12-10 10:04:48
问题 I am looking for the best way to pass either of two arguments to the views from the URL, without allowing any additional arguments. For example, with the following URLs: (r'^friends/requests', 'app.views.pendingFriends'), (r'^friends/offers', 'app.views.pendingFriends'), If it's possible to pass the URL to the views, so that pendingFriends knows which URL it was called from, that would work. However, I can't see a way to do this. Instead, I could supply the arguments ( requests or offers ) in

Django - how can I get permalink to work with “throwaway” slug

╄→гoц情女王★ 提交于 2019-12-09 13:34:49
问题 I'm trying to add slugs to the url in my django app, much like SO does. Currently, I have pages that work just fine with a url like this: http://example.com/foo/123/ I'd like to add 'slugified' urls like so: http://example.com/foo/123/foo-name-here I can get it to work just fine, by simply modifying the urlconf and adding a throwaway value to the view function: #urls.py ulpatterns = patterns('project.app.views', url(r'^foo/(?P<foo_id>\d+)/(?P<name_slug>\w+)/$', 'foo_detail', name='foo_detail'

{% url %} gives me NoReverseMatch error while reverse() returns the url just fine. Why?

你离开我真会死。 提交于 2019-12-09 04:46:40
问题 I don't know if this SO question is of the same problem that I am about to describe, but it does share the same symptoms. Unfortunately, it still remains unresolved as I am writing. So here is my problem. I am trying to add James Bennett's django-registration app to my django project. I have pretty much finished configuring it to my needs - custom templates and urls. Just when I thought everything was good to go. I got NoReverseMatch error from using {% url 'testing' item_id=123 %} (I also

Django-axes not working with custom login view

不想你离开。 提交于 2019-12-08 13:27:02
问题 I have followed the below links before asking this question as it seems like a duplicate, but of no use. So I'm asking again. Django login with django-axes django-axes not capturing failed login attempt, but captures admin failed attempts fine The django-axes works fine with the admin site, but it is unable to capture the failed attempts from the user custom login view. My custom view at '/project/app/views.py' is as follows: from axes.decorators import watch_login @watch_login def user_login

Login URL using authentication information in Django

半城伤御伤魂 提交于 2019-12-08 12:20:24
问题 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_response('index.html', {}, context_instance = RequestContext(request)) def login(request): if request.method == "POST": post = request.POST.copy() if post.has_key(

Django — Redirecting Views with Parameters

放肆的年华 提交于 2019-12-08 10:45:35
问题 In the Django app I am building I would like to have the user creation process go as follows: As user signs up, if valid is then redirected to create a LIST object, and if valid is then redirected to what will be a dashboard for the LIST object just created. My views.py are as follows: def user_signup(request): if request.method == 'POST': form = forms.UserSignupForm(data=request.POST) if form.is_valid(): user = form.save() g = Group.objects.get(name='test_group') g.user_set.add(user) # log

Combining more than one slug in the url

自古美人都是妖i 提交于 2019-12-08 05:14:00
问题 I'm trying to use two slug for generate the urls of a type of post. My site is divided in category and everyone of these have one or more post. views.py def singlePost(request, slug_post): blogpost = get_object_or_404(BlogPost, slug_post=slug_post) context = {"blogpost": blogpost} return render(request, "blog/single_post.html", context) def singleCategory_postList(request, slug_category): category = get_object_or_404(Category, slug_category=slug_category) blogpost = BlogPost.objects.filter