django-urls

How can you dispatch on request method in Django URLpatterns?

不问归期 提交于 2019-12-22 01:53:19
问题 It's clear how to create a URLPattern which dispatches from a URL regex: (r'^books/$', books), where books can further dispatch on request method: def books(request): if request.method == 'POST': ... else: ... I'd like to know if there is an idiomatic way to include the request method inside the URLPattern, keeping all dispatch/route information in a single location, such as: (r'^books/$', GET, retrieve-book), (r'^books/$', POST, update-books), (r'^books/$', PUT, create-books), 回答1: The

Django and Nginx try_files 403 for site root page

筅森魡賤 提交于 2019-12-21 22:10:19
问题 I use such Nginx configuration for the domain: server_name_in_redirect off; listen 80; server_name ~^(www\.)?(.+)$; root /var/www/$2/htdocs; location / { try_files $uri $uri/ $uri/index.htm @django; index index.html index.htm; } location @django { fastcgi_pass 127.0.0.1:8801; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param QUERY_STRING $query_string; fastcgi_param SERVER_NAME $server_name; fastcgi_param SERVER_PORT $server_port;

Advantages of using REST over simple URL and view creation in Django?

我们两清 提交于 2019-12-21 20:18:07
问题 It might be a silly question for many, but why can't I instead Create a view in django that takes a request and returns HttpResponse in, say, JSON format Map the view to a URL Hit the URL from my browser or another server and use the result? Thanks. EDIT - Two approaches: Import some djangorestframework or tastypie and build an api in my application which will throw json responses VS building a class based view and tell it to return json response . Is there any huge advantage of using the

How to pass variables with spaces through URL in :Django

风流意气都作罢 提交于 2019-12-21 12:03:03
问题 I am having trouble in passing variables with spaces in them through the urls. Now Suppose I have an object class Kiosks(models.Model): name = models.CharField(max_length = 200, unique = True) owner = models.ForeignKey(User) Now the "name" entered for kiosk is say "Akash Deshpande" and saved. Now while redirecting to a new page in the views, i am using the "kiosk name " i.e. messages.success(request,"Kiosk edited successfully") return HttpResponseRedirect('/kiosks/'+kiosk.name+'/') The view

Django problem of resolving special characters in url

风流意气都作罢 提交于 2019-12-21 04:29:17
问题 We have a website made by Django. And there is no problem when access following url on local working environment: http://site/tags/c%23/ "c%23" is urlencode of "c#", that works fine locally. But after we deploy it on Bluehost hosting server (apache+fastcgi), this URL has been resolved to a new address like this: http://site/t/tags/c/ That's too weird. Probably it's not a Django's problem, but have something to do with Apache url's rewrite. If you have any idea or suggestion how to fix this

My Django URLs not picking up dashes

允我心安 提交于 2019-12-20 10:26:21
问题 Im trying to work out a url that will match domain.com\about-us\ & domain.com\home\ I have a url regex: ^(?P<page>\w+)/$ but it won't match the url with the - in it. I've tried ^(?P<page>\.)/$ ^(?P<page>\*)/$ but nothing seems to work. 回答1: Try: ^(?P<page>[-\w]+)/$ [-\w] will accept a-z 1-9 and dash 来源: https://stackoverflow.com/questions/531243/my-django-urls-not-picking-up-dashes

404 error in django when visiting / Runserver returns no errors though

£可爱£侵袭症+ 提交于 2019-12-20 06:22:21
问题 When I syncdb and runserver everything works correctly in Django, but when I try to visit the webpage that it is on http://127.0.0.1:8000/ it returns a 404 error. Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in MyBlog.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, , didn't match any of these. The strange part is that when I visit /admin on the page it works fine. I dont understand what is failing here.

Using object's id in change_form_object_tools.html template

放肆的年华 提交于 2019-12-20 05:52:20
问题 I have two buttons that appointing to different paths. And i want to pass the object.id with parameter. my urls urlpatterns = [ path('', admin.site.urls, name ='home'), path('dpo/imprimir/aprovado/<int:id>/',Aprovado, name ='aprovado'), path('dpo/imprimir/reprovado/<int:id>/',Reprovado, name ='reprovado'), ] My views from django.http import HttpResponse from django.shortcuts import render from django.shortcuts import render_to_response from .models import Projeto def Aprovado(request, id):

Tastypie- Append parameters to URI

这一生的挚爱 提交于 2019-12-20 05:41:13
问题 How do I append parameters to a URL in Django Tastypie. Here is url.py. from modules.actions.views import InstallationResource,ApiActionsResource from tastypie.api import Api from modules.actions import views v1_api = Api(api_name='v1') v1_api.register(ApiActionsResource()) urlpatterns = patterns('', url(r'^(?P<action_type>.+)', views.ApiActionsResource.as_view), ) I need to pass action_type=1 to the URL. How do I do it? 回答1: You need to include your api urls like this: urlpatterns = patterns

TypeError when concatenating django.test.LiveServerTestCase's live_server_url with another string

三世轮回 提交于 2019-12-20 03:16:48
问题 Whenever I try to construct a string based on self.live_server_url , I get python TypeError messages. For example, I've tried the following string constructions (form 1 & 2 below), but I experience the same TypeError . My desired string is the Live Server URL with "/lists" appended. NOTE: the actual test does succeed to create a server and I can manually access the server, and more specifically, I can manually access the exact URL that I'm trying to build programmatically (e.g. 'http:/