标签: django-wsgi

为什么我们必须在Django设置中提供WSGI_APPLICATION变量

我是Django初学者,所以如果这个问题没有道理,请原谅我。

我们提供了一个WSGI_APPLICATION在Django设置中称为的变量,ROOT_URLCONF以及其他一些设置变量。并且我们还在wsgi.py文件中提供了设置文件路径,

import os
import django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGSS_MODULE", "<settings_file_path>")
application = get_wsgi_application()
Run Code Online (Sandbox Code Playgroud)

如此看来,它是双向连接。对吗?

我的意思是wsgi文件中的设置文件路径和wsgi文件中的wsgi文件路径。那么为什么我们必须这样做。

根据我对wsgi文件中设置文件的理解路径,应该足够好,而我们在Django设置中不需要该额外的变量吗?

最终,wsgi文件是django应用程序的起点,对吗?

请在错误之处纠正我。

python django django-wsgi django-settings

5
推荐指数
1
解决办法
5676
查看次数

pip install mod_wsgi在virtualenv中失败

我想在virtualenv中的mac os 10.12上使用python 2.7.10中的pip安装mod_wsgi.我打算在Django 1.10.3中使用它.当我运行"pip install mod_wsgi"时,我得到以下输出:

Collecting mod_wsgi
Using cached mod_wsgi-4.5.7.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/sf/kdqqs98d06326180mss7hggh0000gn/T/pip-build-hgA7s1/mod-wsgi/setup.py", line 247, in <module>
    APR_INCLUDES = get_apr_includes().split()
  File "/private/var/folders/sf/kdqqs98d06326180mss7hggh0000gn/T/pip-build-hgA7s1/mod-wsgi/setup.py", line 219, in get_apr_includes
    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

----------------------------------------
Command "python setup.py egg_info" failed with error code …
Run Code Online (Sandbox Code Playgroud)

django mod-wsgi virtualenv django-wsgi python-2.7

5
推荐指数
1
解决办法
3895
查看次数

Django发送分块响应

我的设置是 Django->Gunicorn->Nginx

虽然我不使用HttpStreamingResponse,但浏览器看到Transfer-encoding: chunked这会导致 Cloudfront 出现问题(它不会自动压缩分块响应)

我的 gunicorn 使用默认值运行,所以默认工作人员等,我在 nginx 中找不到任何关于此的选项。

我应该停止使用分块吗?如果是这样怎么办?

我发现这个https://github.com/abrookins/streaming_django提到

First, some conditions must be true:

- The client must be speaking HTTP/1.1 or newer
- The request method wasn't a HEAD
- The response does not include a Content-Length header
- The response status wasn't 204 or 304

If these conditions are true, then Gunicorn will add a Transfer-Encoding: chunked header to the response, signaling to the client that the …
Run Code Online (Sandbox Code Playgroud)

django wsgi nginx django-wsgi gunicorn

5
推荐指数
0
解决办法
599
查看次数

如何为 Django 启用 WSGIPassAuthorization?

我正在测试 Django API 端点,但我需要启用 WSGIPassAuthorization 才能接收 Authorization 标头。我应该在哪里启用它?

PS:我使用的是 macOS,但任何答案都可能有用!

django mod-wsgi wsgi django-wsgi django-rest-framework

5
推荐指数
1
解决办法
7443
查看次数

使用 mod_wsgi 在 apache 上部署 django 应用程序时出现“没有名为‘编码’的模块”错误

版本列表:

Centos 7 --- django 2.1.7 --- Apache 2.4.6 --- Python 3.6

检查EDIT 5以获取最新的错误日志

在此处遵循本教程:https : //www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7

我能够运行sudo systemctl start httpd,当我转到 url 时,我收到内部服务器错误(底部的日志)

我的文件结构

home
??? user
    ??? projects
        ??? myapp
            ??? app
            ?   ??? <All Code for Webapp including static dir>  
            ??? env (virtualenv)
            ??? manage.py
            ??? new
            ?   ??? settings.py
            ?   ??? urls.py
            ?   ??? wsgi.py
            ??? requirements.txt
Run Code Online (Sandbox Code Playgroud)

我希望有人能在我的 httpd 文件夹下的 django.conf 中看到错误。希望这些是我正在寻找的终点

编辑:该文件位于:/etc/httpd/conf.d/django.conf

django.conf

Alias /static /home/user/projects/myapp/app/static
<Directory /home/user/projects/myapp/app/static>
    Require all granted …
Run Code Online (Sandbox Code Playgroud)

apache django mod-wsgi django-wsgi

5
推荐指数
1
解决办法
2617
查看次数

使用带有 dotenv 的 Django 堆栈通过 WSGI 查找 .env 时出现问题

我有一个 Django 应用程序,我正在尝试使用 dotenv 来保护我的 SECRET_KEY 。manage.py runserver 工作正常,但使用 apache2 托管的站点无法工作,并且 apache 给我错误日志:

mod_wsgi (pid=32200): Failed to exec Python script file '/opt/bitnami/projects/accuhx/accuhx/wsgi.py'.
mod_wsgi (pid=32200): Exception occurred processing WSGI script '/opt/bitnami/projects/accuhx/accuhx/wsgi.py'.
Traceback (most recent call last):
File "/opt/bitnami/projects/accuhx/accuhx/wsgi.py", line 23, in <module>
 application = get_wsgi_application()
File "/opt/bitnami/python/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/bitnami/python/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
   configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/opt/bitnami/python/lib/python3.8/site-packages/django/conf/__init__.py", line 83, in __getattr__
    self._setup(name)
File "/opt/bitnami/python/lib/python3.8/site-packages/django/conf/__init__.py", line 70, in _setup
self._wrapped = Settings(settings_module)
File "/opt/bitnami/python/lib/python3.8/site-packages/django/conf/__init__.py", line 196, in …
Run Code Online (Sandbox Code Playgroud)

django wsgi apache2 django-wsgi

5
推荐指数
1
解决办法
1995
查看次数

决定使用WSGI或Django获取新的Web应用程序

我正在建立一个新的Web应用程序并决定是使用WSGI还是使用Django进行完整的框架路由.

该应用程序的首要要求:

1)应用程序没有任何UI,所有数据都通过带有JSON的REST api向客户端公开.

2)它将保留数据,因此MongoDB和可能亚马逊的SimpleDB将用于数据库端.

是否有理由使用Django或者我是否只能通过WSGI获得边际速度提升?

我构建的以前的服务器端应用程序在JVM上使用Java/Struts和Groovy/Grails.我的理解是Django是一个类似于Rails和Grails的MVC框架.

我还玩过Google App Engine,它使用WSGI作为代码上方的薄层来管理和路由请求.

python django wsgi django-wsgi

4
推荐指数
1
解决办法
204
查看次数

/ admin / login /的Django :: OperationalError无法打开数据库文件

我知道已经有一个同样的问题,我也尝试过的解决方案,由于其但它力的工作对我来说因此我写我自己的问题。大家好,我正在使用apache2服务器部署django服务器,当我尝试我的主机ip地址时,它可以正常工作,因为它显示了它的“工作页面”,它也适用于IPADRESS / admin,但是在填写凭据并按Enter后,将产生此错误

***OperationalError at /admin/login/
unable to open database file***
Run Code Online (Sandbox Code Playgroud)

我的错误看起来像

Environment:


Request Method: POST
Request URL: http://192.168.1.105/admin/login/?next=/admin/

Django Version: 1.7.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'managementdashboard')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/contrib/admin/sites.py" in login
  361.         return …
Run Code Online (Sandbox Code Playgroud)

django django-admin django-wsgi django-permissions

4
推荐指数
1
解决办法
5409
查看次数

如何让Django管理URL只能访问localhost?

使Django/admin/urls只能访问localhost的最简单方法是什么?

我想到的选项:

  • 将管理站点分离出项目(以某种方式)并作为不同的虚拟主机运行(在Apache2中)
  • 在托管(Apache2)Web服务器前使用代理
  • 以某种方式限制WSGI中的Apache中的URL.

有标准方法吗?

谢谢!

python apache django wsgi django-wsgi

3
推荐指数
1
解决办法
1808
查看次数

“ WSGIRequest”对象没有属性“ LANGUAGE_CODE”

当我禁用 cms.middleware.multilingual.MultilingualURLMiddleware

'WSGIRequest' object has no attribute 'LANGUAGE_CODE' 在编辑页面或使用{% show_menu_below_id %}标记时渲染时遇到异常。

我不需要lang前缀,请帮助我禁用此东西。

django-wsgi django-cms

1
推荐指数
1
解决办法
2234
查看次数

Django WSGIRequest 参数错误

AttributeError("'WSGIRequest' object has no attribute 'args'",) 当我尝试拨打这个电话时,我得到了这个

GET /sign_s3/?s3_object_type=image/jpeg&s3_object_name=default_name

我错过了什么吗?

*args, **kwargs除了请求,我还需要包括吗?

这是回溯:

            response = middleware_method(request, callback, callback_args, callback_kwargs)
            if response:
                break
    if response is None:
        wrapped_callback = self.make_view_atomic(callback)
        try:
            response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
        except Exception as e:
            # If the view raised an exception, run it through exception
            # middleware, and if the exception middleware returns a
            # response, use that. Otherwise, reraise the exception.
            for middleware_method in self._exception_middleware:
                response = middleware_method(request, e)
Run Code Online (Sandbox Code Playgroud)

风景:

@login_required()
def …
Run Code Online (Sandbox Code Playgroud)

python django django-wsgi

1
推荐指数
1
解决办法
6735
查看次数

Gunicorn不会用WSGI运行Django

我试图用gunicorn运行我的django项目,但是收到错误.要测试我通过运行以下命令创建了所有新内容:

virtualenv test_gunicorn
source test_gunicorn/bin/activate
pip install django gunicorn
cd test_gunicorn/
mkdir projects
cd projects/
django-admin startproject test_gunicorn
cd test_gunicorn/
gunicorn test_gunicorn/wsgi:application
Run Code Online (Sandbox Code Playgroud)

但仍然得到了与原始项目相同的错误.以下是错误:

[2015-07-13 14:22:33 +0000] [9122] [INFO] Starting gunicorn 19.3.0
[2015-07-13 14:22:33 +0000] [9122] [INFO] Listening at: http://127.0.0.1:8000 (9122)
[2015-07-13 14:22:33 +0000] [9122] [INFO] Using worker: sync
[2015-07-13 14:22:33 +0000] [9127] [INFO] Booting worker with pid: 9127
[2015-07-13 14:22:33 +0000] [9127] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File …
Run Code Online (Sandbox Code Playgroud)

python django django-wsgi gunicorn

1
推荐指数
1
解决办法
4999
查看次数