django-urls

Django and Nginx try_files 403 for site root page

本小妞迷上赌 提交于 2019-12-04 17:07:47
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; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param

Django 'resolve' : get the url name instead of the view_function

a 夏天 提交于 2019-12-04 16:24:08
问题 My problem is simple, I have an url, I would like to resolve it, but get the url name instead of the view function associated with it ... For example... this is urlconf : urlpatterns = patterns('', ... url('^/books/$', book_list, name="overview_books"), ... ) And this is what I would like : >>> resolve('/books/') 'overview_books' Do you know any way to do this ? 回答1: Use this snippet (originally taken from djangosnippets.org/snippets/1378/ ); >>> from my_projects.tools import resolve_to_name

How to display custom 404.html page in Django

做~自己de王妃 提交于 2019-12-04 15:48:26
问题 I want to display custom 404 error page when end user enters wrong url,I have tried but i am getting only Django default 404 page.I am using Python(2.7.5),Django(1.5.4) My Code urls.py from django.conf.urls import patterns, include, url from mysite import views handler404 = views.error404 urlpatterns = patterns('', url(r'^$', 'mysite.views.home', name='home'), ) views.py from django.http import HttpResponse from django.shortcuts import render from django.template import Context, loader def

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

瘦欲@ 提交于 2019-12-04 12:29:51
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 first one? I think you could make the same argument about any extension library. It just depends on how

why my urls.py does't work with Django

会有一股神秘感。 提交于 2019-12-04 05:30:56
问题 Today when I code my blog with 'Building_a_blog_in_30_mins_with_Django_Screencast',I meet some problems.When I click the title with the article,it can't appear the right page.! Page not found (404) Request Method: GET Using the URLconf defined in myblog.urls, Django tried these URL patterns, in this order: ^$ ^(?P<pk>\d+)/$ ^admin/ ^admin/doc/ The current URL, app/1, didn't match any of these. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to

Django ignoring changes made to URLS.py file - Amazon AWS

妖精的绣舞 提交于 2019-12-04 04:26:40
问题 I just created an EC2 instance and created a Django app and am using Amazon servers. Normally when I make a change to my Djnago app, I updated it by doing git add . git commit -m "change" git aws.push I recently made changes to my URLS.py file and did the three steps above. I then went to my website and for some reason when I visit a URL, it gives a 404 not found error and says Using the URLconf defined in myapp.urls, Django tried these URL patterns, in this order: 1. ^$ The current URL,

django getting the absolute path of a FileField

女生的网名这么多〃 提交于 2019-12-04 00:03:56
I am trying to retrieve the absolute path (starting with http://) while calling a FileField at the template. How can I achieve this ? ie: {{fl.uploadedfile}} -> returns relative path like media/uploads/ while I want This Cheers The Django File object provides several convenience functions/attributes, one of which is the URL associated with the file. In this case, as you pointed out, you're looking for the url attribute. Just found the answer: adding .url fixes this issue fixes it such as {{fl.uploadedfile.url}} 来源: https://stackoverflow.com/questions/1211527/django-getting-the-absolute-path-of

Django HttpResponseRedirect vs render_to_response - how to get a login form to behave the way I need it to

谁都会走 提交于 2019-12-03 21:55:34
I've already checked out the following stackoverflow question regarding the difference between HttpResponse, HttpResponseRedirect, and render_to_response , as well as having gone through the official django docs, but I'm really uncertain how best to get the functionality I'm looking to create. Right now I have an index.html with a login function (as seen in the views.py below) where the render_to_response that brings me to portal/index.html . However, as urls.py (see below) dictates, the url in the url bar of my browser is http://127.0.0.1:8000/login/ . This means that refreshing the page

Django: Slug in Vietnamese

一个人想着一个人 提交于 2019-12-03 20:27:08
问题 A site in Vietnamese, it is virtually no different to English. However, there is a problem that is slug. When I type characters such as "ư", "ơ", "á",... Django is not identified. Solution here is to replace characters that do not sign into. Eg: ư -> u ơ -> o á -> a One from "những-viên-kẹo" will become "nhung-vien-keo". However, I do not know how to do this. Someone help me. Thank you very much! 回答1: [edit] I take it back, django's django.template.defaultfilters.slugify() does what you want,

Getting 404 not found using path() in Django

ε祈祈猫儿з 提交于 2019-12-03 18:12:02
问题 I was just checking out django, and was trying a view to list the books by passing id as an argument to the URL books/urls.py . But getting 404 page not found error. I'm not getting whats wrong in the url when I typed this url in the browser: http://192.168.0.106:8000/books/list/21/ bookstore/urls.py urlpatterns = [ path('admin/', admin.site.urls), path('books/', include("books.urls")) ] settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes