Django部署的问题, nginx + uwsgi

tyzyx 2018-05-21 09:21:45
问题

通过 nginx + uwsgi 部署后,访问一些特定的地址,django会提示404
但是用runserver 或 uwsgi 起动Python服务没有问题,地址都可以正常访问

出问题的APP中用到了单独的urls.py,代码如下:


urlpatterns = [
url(r'^respond$', views.ResponseView.as_view(),
name='answer'), # 回调函数
]
在view中用了这个方法取得地址
reverse("answer"))


nginx的config如下


server {
listen 80;
server_name www.test.com;
charset utf-8;

client_max_body_size 75M;

access_log /home/ubuntu/access.log
location / {
uwsgi_pass unix:///home/ubuntu/test.sock;
include /etc/nginx/uwsgi_params;
}
}

请问这个问题如何处理?
...全文
1183 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyzyx 2018-06-13
  • 打赏
  • 举报
回复
引用 5 楼 xpresslink 的回复:
把这个文件 /etc/nginx/uwsgi_params; 内容贴上来 另外在urls.py 里面要加上 app_name='your_app_name' # 要和 settings.py 中INSTALLED_APPS=[...., ']中注册的那个是相同的。 反向解析时候要用 reverse(' your_app_name: answer')
urls.py 里面要加上 app_name='your_app_name' 这段加在哪里呢? /etc/nginx/uwsgi_params; 内容如下,默认的没有任何修改 uwsgi_param QUERY_STRING $query_string; uwsgi_param REQUEST_METHOD $request_method; uwsgi_param CONTENT_TYPE $content_type; uwsgi_param CONTENT_LENGTH $content_length; uwsgi_param REQUEST_URI $request_uri; uwsgi_param PATH_INFO $document_uri; uwsgi_param DOCUMENT_ROOT $document_root; uwsgi_param SERVER_PROTOCOL $server_protocol; uwsgi_param REQUEST_SCHEME $scheme; uwsgi_param HTTPS $https if_not_empty; uwsgi_param REMOTE_ADDR $remote_addr; uwsgi_param REMOTE_PORT $remote_port; uwsgi_param SERVER_PORT $server_port; uwsgi_param SERVER_NAME $server_name;
tyzyx 2018-05-25
  • 打赏
  • 举报
回复
引用 3 楼 oyljerry 的回复:
[quote=引用 2 楼 tyzyx的回复:][quote=引用 1 楼 oyljerry 的回复:] 需要逐步排除,一个是Nginx是否有对应的路径,其次请求有没有转发到uwsgi,然后django中有没有正确处理对应路径
请求转发到uwsgi了,django提示没有对应的地址 具体错误如下: Internal Server Error: /respond Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 235, in get_response response = middleware_method(request, response) File "/usr/local/lib/python3.5/dist-packages/django/middleware/common.py", line 113, in process_response if response.status_code == 404: AttributeError: 'ResponseView' object has no attribute 'status_code' [/quote] 你的responseview没有返回HttpResponse[/quote] 但是用runserver 或 uwsgi 起动Python服务没有问题,地址都可以正常访问
混沌鳄鱼 2018-05-25
  • 打赏
  • 举报
回复
把这个文件 /etc/nginx/uwsgi_params; 内容贴上来 另外在urls.py 里面要加上 app_name='your_app_name' # 要和 settings.py 中INSTALLED_APPS=[...., ']中注册的那个是相同的。 反向解析时候要用 reverse(' your_app_name: answer')
oyljerry 2018-05-24
  • 打赏
  • 举报
回复
引用 2 楼 tyzyx的回复:
[quote=引用 1 楼 oyljerry 的回复:] 需要逐步排除,一个是Nginx是否有对应的路径,其次请求有没有转发到uwsgi,然后django中有没有正确处理对应路径
请求转发到uwsgi了,django提示没有对应的地址 具体错误如下: Internal Server Error: /respond Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 235, in get_response response = middleware_method(request, response) File "/usr/local/lib/python3.5/dist-packages/django/middleware/common.py", line 113, in process_response if response.status_code == 404: AttributeError: 'ResponseView' object has no attribute 'status_code' [/quote] 你的responseview没有返回HttpResponse
tyzyx 2018-05-24
  • 打赏
  • 举报
回复
引用 1 楼 oyljerry 的回复:
需要逐步排除,一个是Nginx是否有对应的路径,其次请求有没有转发到uwsgi,然后django中有没有正确处理对应路径
请求转发到uwsgi了,django提示没有对应的地址 具体错误如下: Internal Server Error: /respond Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 235, in get_response response = middleware_method(request, response) File "/usr/local/lib/python3.5/dist-packages/django/middleware/common.py", line 113, in process_response if response.status_code == 404: AttributeError: 'ResponseView' object has no attribute 'status_code'
oyljerry 2018-05-21
  • 打赏
  • 举报
回复
需要逐步排除,一个是Nginx是否有对应的路径,其次请求有没有转发到uwsgi,然后django中有没有正确处理对应路径

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧