传递任何 url 参数时,Django 管理面板会抛出 404 示例 url:
/admin/app/model/ - 好的
/admin/app/model/?foo=bar - 404
/admin/app/model/?p=1 - 404
Nginx+uwsgi
项目 urls 文件(admin、admin_tools、application urls)
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
import restaurant.views
import club.views
import hotel.views
import custom_app.views
import cart.views
from django.views.decorators.csrf import csrf_exempt
from django.contrib import admin
import settings
handler404 = 'custom_app.views.handler404'
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin_tools/', include('admin_tools.urls')),
(r'^$', custom_app.views.Index.as_view()),
(r'^restaurant$', restaurant.views.Index.as_view()),
(r'^which$', csrf_exempt(TemplateView.as_view(template_name='custom_app/which.html'))),
(r'^cart/add', cart.views.AddToCart.as_view()),
(r'^cart/delete', cart.views.RemoveFromCart.as_view()),
(r'^cart/send', cart.views.SendCart.as_view()),
(r'^cart/delivery', cart.views.SetDelivery.as_view()),
(r'^restaurant/about', restaurant.views.About.as_view()),
(r'^restaurant/payment', restaurant.views.Payment.as_view()),
(r'^restaurant/vip', restaurant.views.Vip.as_view()),
(r'^restaurant/menu/(?P<slug>.+)', restaurant.views.Menu.as_view()),
(r'^restaurant/menu/', restaurant.views.Menu.as_view()),
(r'^restaurant/cart/', cart.views.Basket.as_view()),
(r'^restaurant/tables/', restaurant.views.Tables.as_view()),
(r'^restaurant/success_ordering', restaurant.views.SuccesTableOrder.as_view()),
(r'^vacancy', custom_app.views.Vacancy.as_view()),
(r'^hotel$', hotel.views.Main.as_view()),
(r'^hotel/services', hotel.views.Services.as_view()),
(r'^hotel/room/(?P<room>\d+)$', hotel.views.Main.as_view()),
(r'^hotel/order/option/toggle$', hotel.views.ToggleOption.as_view()),
(r'^hotel/order/date/toggle$', hotel.views.ToggleDate.as_view()),
(r'^hotel/order/send$', hotel.views.Send.as_view()),
(r'^club/events/old/(?P<year>\d+)/(?P<month>\d+)', club.views.OldEvents.as_view()),
(r'^club/events/old/', club.views.OldEvents.as_view()),
(r'^club/about', club.views.About.as_view()),
(r'^club/event/(?P<pk>\d+)', club.views.DetailEvent.as_view()),
(r'^club$', club.views.Main.as_view()),
url(r'^admin/', include(admin.site.urls)),
(r'^ckeditor/', include('ckeditor.urls')),
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
Nginx 配置文件:
server
{
listen %server_ip%;
server_name custom.ru www.custom.ru;
root /home/custom/www/;
location ~* ^/resize/([\d\-]+)/([\d\-]+)/(.+)$ {
alias /home/custom/www/custom/$3;
image_filter resize $1 $2;
image_filter_buffer 2M;
error_page 415 = /empty;
}
location ~* ^/crop/([\d\-]+)/([\d\-]+)/(.+)$ {
alias /home/custom/www/custom/$3;
image_filter crop $1 $2;
image_filter_buffer 2M;
error_page 415 = /empty;
}
location = /empty {
empty_gif;
}
location /
{
root /home/custom/www/custom/;
uwsgi_pass unix:///home/custom/tmp/uwsgi.sock;
include uwsgi_params;
uwsgi_param UWSGI_PASS unix:///home/custom/tmp/uwsgi.sock;
uwsgi_param UWSGI_CHDIR /home/custom/www/custom/;
uwsgi_param UWSGI_SCRIPT wsgi;
}
location /static
{
alias /home/custom/www/custom/static/;
}
location /media
{
alias /home/custom/www/custom/media/;
}
location = /favicon.ico { alias /home/custom/www/favicon.ico; }
}