django-urls

The included urlconf manager.urls doesn't have any patterns in it

让人想犯罪 __ 提交于 2019-11-29 03:01:39
A solution: Found the following django snippet that seems to work fine ( http://djangosnippets.org/snippets/2445/ ) from django.utils.functional import lazy from django.core.urlresolvers import reverse #Workaround for using reverse with success_url in class based generic views #because direct usage of it throws an exception. reverse_lazy = lambda name=None, *args : lazy(reverse, str)(name, args=args) Apparently, there is now a reverse_lazy function in django trunk. Update: This error has something to do with me making a call to reverse inside a generic view: class AddObjView(CreateView): form

Django's HttpResponseRedirect seems to strip off my subdomain?

自作多情 提交于 2019-11-29 02:46:37
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 sub-domain? SmileyChris Django has some methods it always applies to a response. One of these is django

Recursive URL Patterns CMS Style

孤街浪徒 提交于 2019-11-29 02:08:21
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/grandchild/ would return parent, child, grandchild. So is this something that Django does already? Or do I

Django UpdateView without pk in url

南笙酒味 提交于 2019-11-29 01:56:35
Is it possible eliminate pk from url related to UpdateView ? For example, if I have url(r'^myobj/update/(?P<pk>\d+)/$', views.UpdateMyObj.as_view(), name="update") is there any way to write it like url(r'^myobj/update/$', views.UpdateMyObj.as_view(), name="update") and then send pk as a parameter in POST or GET request? Yes it is possible you just need to override the get_object method: from django.views.generic.edit import UpdateView class UpdateMyObj(UpdateView): # ..... def get_object(self): return MyModel.objects.get(pk=self.request.GET.get('pk')) # or request.POST 来源: https:/

For a django model, how can I get the django admin URL to add another, or list objects, etc.?

怎甘沉沦 提交于 2019-11-28 22:25:40
问题 As much as I love the django documentation, the section on bookmarklets in the admin is strangely vague. My question is this: If I'm in a view and I have a django model (or, in some cases, an actual object), how can I get to the relevant admin pages for that model (or object)? If I have the object coconut_transportation.swallow.objects.all()[34], how can I jump right to the admin page to edit that particular swallow? Likewise, how can I get the URL for the admin page to add another swallow?

Django: What is the difference b/w HttpResponse vs HttpResponseRedirect vs render_to_response

点点圈 提交于 2019-11-28 17:54:21
问题 The above mentioned things are giving me almost the same results was wondering whats the main difference in them. 回答1: response = HttpResponse("Here's the text of the Web page.") : will create a new HttpResponse object with HTTP code 200 (OK), and the content passed to the constructor. In general, you should only use this for really small responses (like an AJAX form return value, if its really simple - just a number or so). HttpResponseRedirect("http://example.com/") : will create a new

Using {% url ??? %} in django templates

风流意气都作罢 提交于 2019-11-28 15:56:55
I have looked a lot on google for answers of how to use the 'url' tag in templates only to find many responses saying 'You just insert it into your template and point it at the view you want the url for'. Well no joy for me :( I have tried every permutation possible and have resorted to posting here as a last resort. So here it is. My urls.py looks like this: from django.conf.urls.defaults import * from login.views import * from mainapp.views import * import settings # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns

Anyone knows good Django URL namespaces tutorial? [closed]

那年仲夏 提交于 2019-11-28 15:39:41
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm looking for a good tutorial for URL namespaces in Django. I find official documentation a little too sparse - it lacks good examples. I found similar question here on stack, but the answers didn't help me to fully understand the subject either. 回答1: Agreed, the docs for this are rather confusing. Here's my

Any /polls URL always call index() function in views.py

一个人想着一个人 提交于 2019-11-28 14:44:43
polls/urls/py from django.conf.urls import url from . import views urlpatterns = [ url('', views.index, name='index'), url('<int:question_id>/', views.detail, name='detail'), # ex: /polls/5/results/ url('<int:question_id>/results/', views.results, name='results'), # ex: /polls/5/vote/ url('<int:question_id>/vote/', views.vote, name='vote'), ] views.py from __future__ import unicode_literals from django.http import HttpResponse from .models import Question from django.template import loader # from django.shortcuts import render def index(request): latest_question_list = Question.objects.order

Django and service workers - serve “sw.js” at application's root url

北城以北 提交于 2019-11-28 10:11:23
So I'm building a Django progressive web app with offline support using service workers. According to google's documentation , the sw.js file should be at the root of the app's url: You need to do this because the scope of a service worker (the set of urls that the ServiceWorker will load for) is defined by the directory where it resides. At the moment, I'm serving all static assets from http://example.com/static/ folder. But I need to serve this specific file at a url like: http://example.com/sw.js . Any idea how I can achieve this? I could make a specific nginx rule to do this redirection,