我在apache 1and1共享主机上使用Django 2.0.9和Python 3.4.2。
当我向Djando应用程序发出任何POST HTTP请求时,会收到以下消息:
跟踪:
文件“ ... / python3.4 / site-packages / django / core / handlers / exception.py” 在内部 35. response = get_response(request)
文件“ ... / python3.4 / site-packages / django / core / handlers / base.py”位于 _get_response 119. response = middleware_method(request,callback,callback_args,callback_kwargs)
文件“ ... / python3.4 / site-packages / django / middleware / csrf.py”在 process_view 289. request_csrf_token = request.POST.get('csrfmiddlewaretoken','')
文件“ ... / python3.4 / site-packages / django / core / handlers / wsgi.py”在 _get_post 115. self._load_post_and_files()
文件“ ... / lib / python3.4 / site-packages / django / http / request.py”位于 _load_post_and_files 302. self._post,self._files = QueryDict(self.body,encoding = self._encoding),MultiValueDict()
正文中的文件“ ... / python3.4 / site-packages / django / http / request.py” 263. self._body = self.read()
读取文件“ ... / python3.4 / site-packages / django / http / request.py” 322. return self._stream.read(* args,** kwargs)
文件“ ... / python3.4 / site-packages / django / core / handlers / wsgi.py”在 读 36. result = self.buffer + self._read_limited()
异常类型:/ adminlogin /处的TypeError异常值:不能 将字节连接到str
我发布了管理员登录页面的踪迹,但是任何POST请求都存在相同的问题。
这是我的设置。py:
#Cookie Domain
CSRF_COOKIE_DOMAIN='mydomain.es'
SESSION_COOKIE_DOMAIN = ['mydomain.es', 'www.mydomain.es', 'localhost']
BASE_URL='mydomain.es'
CSRF_TRUSTED_ORIGINS=['mydomain.es']
ALLOWED_HOSTS = ['localhost', 'mydomain.es', 'www.mydomain.es']
SESSION_EXPIRE_AT_BROWSER_CLOSE=True
Application definition
INSTALLED_APPS = [
'myapp.apps.MyAppConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'import_export',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_inlinecss',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'myapp.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['...myprojectdir/myapp/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'myapp.wsgi.application'
我的.htaccess:
AddHandler cgi-script .fcgi
RewriteEngine on
RewriteBase /
# Set up static content redirect:
RewriteRule ^(static/.*)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(adminmedia/.*)$ - [L]
# The following two lines are for FastCGI:
RewriteCond %{REQUEST_URI} !(application.fcgi)
RewriteRule ^(.*)$ application.fcgi/$1 [QSA,L]
我的application.fcgi:
#!...myenv/bin/python3
import os
import sys
import traceback
from flup.server import *
home = '...'
try:
os.environ['VIRTUAL_ENV'] = os.path.join(home, '...myenv/bin/python')
os.environ['PATH'] = os.environ['VIRTUAL_ENV'] + ':' + os.environ['PATH']
project = os.path.join(home, 'myapp')
# Add a custom Python path.
sys.path.insert(0, project)
# Switch to the directory of your project.
os.chdir(project)
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "myapp.settings"
from django_fastcgi.servers.fastcgi import runfastcgi
from django.core.servers.basehttp import get_internal_wsgi_application
wsgi_application = get_internal_wsgi_application()
runfastcgi(wsgi_application, method="prefork", daemonize="false", minspare=1, maxspare=1, maxchildren=1)
except:
with open(os.path.join(home, 'tmp/error.log'), 'w') as fp:
traceback.print_exc(file = fp)