Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 德扬戈。在此服务器上找不到请求的URL/_Python_Django_Postgresql_Nginx_Gunicorn - Fatal编程技术网

Python 德扬戈。在此服务器上找不到请求的URL/

Python 德扬戈。在此服务器上找不到请求的URL/,python,django,postgresql,nginx,gunicorn,Python,Django,Postgresql,Nginx,Gunicorn,我在CentOS 7上安装了Django 1.9.2项目,但在此服务器上找不到请求的URL/错误。日志不提供任何nGinx错误。在使用manage.py runserver的PC上,它可以正常工作 如何在服务器上安装项目: 我在用这个 -但是我在我的环境中安装了python 3.4.3 -创建了一个项目,项目名称与我在PyCharm中的项目名称相同 -通过FTP将服务器上的项目替换为PyCharm中的我的项目 数据库工作(makemigration,migrate,collectstatic),

我在CentOS 7上安装了Django 1.9.2项目,但在此服务器上找不到请求的URL/错误。日志不提供任何nGinx错误。在使用manage.py runserver的PC上,它可以正常工作

如何在服务器上安装项目:

我在用这个 -但是我在我的环境中安装了python 3.4.3 -创建了一个项目,项目名称与我在PyCharm中的项目名称相同 -通过FTP将服务器上的项目替换为PyCharm中的我的项目

数据库工作(makemigration,migrate,collectstatic),site.com/admin工作,我正在获取位于全局模板文件夹中的自定义404.html页面

DEBUG = False

ALLOWED_HOSTS = [
    '*',
    ]
我的项目结构是:

我的全球网址:

from django.conf.urls import include, url
from django.contrib import admin
from bakot import urls as bakot_urls
from loginsys import urls as loginsys_urls

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include(bakot_urls)),
    url(r'^auth/', include(loginsys_urls)),
]
我的bakot url:

from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from bakot import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^step(?P<step_id>[0-9]+)$', views.step, name='step'),    
    url(r'^question(?P<question_id>[0-9]+)$', views.question, name='question'),
    url(r'^newpage(?P<step_id>[0-9]+)/$', views.new_page,name='newpage'),
    url(r'^lastpage(?P<step_id>[0-9]+)/$', views.last_page,name='lastpage'),
    url(r'^answerset$', views.answerset, name='answerset'),
    url(r'^isperm$', views.isperm, name='isperm'), 

]

古尼康:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=bakotiinii
Group=nginx
WorkingDirectory=/home/bakotiinii/apifolder
ExecStart=/home/bakotiinii/apifolder/djangoen/bin/gunicorn --workers 3 --bind unix:/home/bakotiinii/apifolder/apifolder.sock apifolder.wsgi:application

[Install]
WantedBy=multi-user.target
nGinx

索引

设置.py

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


SECRET_KEY = 'xxx'

DEBUG = False

ALLOWED_HOSTS = [
    '*',
    ]


EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'xxx'
EMAIL_HOST_PASSWORD = 'xxx'
DEFAULT_FROM_EMAIL = 'xxx'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'



# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bakot',
    'loginsys',
)

MIDDLEWARE_CLASSES = (
    '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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'apifolder.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, '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',
                'django.template.context_processors.media'
            ],
        },
    },
]

WSGI_APPLICATION = 'apifolder.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'xxx',
        'USER': 'xxx',
        'PASSWORD': 'xxx',
        'HOST': 'localhost',
        'PORT': '',
    }
}


LANGUAGE_CODE = 'ru-ru'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = (
)
我在我的项目中有两个应用程序。bakot和loginsys,我还尝试将setting.py链接添加到他们的模板中,但没有成功

'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
            os.path.join(BASE_DIR, 'bakot/templates/'),
            os.path.join(BASE_DIR, 'loginsys/templates/'),            
            ]
        , 

如果您转到例如localhost:8000而不使用/,或者使用带有斜杠的url(r'^/$,views.index,name='index'),会发生什么情况?您的nginx配置是什么样子的?那你是怎么招待德扬戈的:古尼康?uwsgi?1)无论有无斜杠,它都会在服务器上给我404错误,在我的本地PC上一切正常。2) 添加gunicorn和nginx设置。您能否显示日志中的完整错误/回溯以及索引视图?添加索引视图,主要问题是:没有任何日志。有些人告诉我,因为我使用nginx作为代理,所以不会有任何日志。
def index(request):
    stepitem = Step.objects.all()
    username = auth.get_user(request).username
    start = Step.objects.get(id = 1)
    argo = {
        "stepitem" : stepitem,
        "username" : username,
        "start" : start,
    }
    return render(request, 'bakot/index.html', argo)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


SECRET_KEY = 'xxx'

DEBUG = False

ALLOWED_HOSTS = [
    '*',
    ]


EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'xxx'
EMAIL_HOST_PASSWORD = 'xxx'
DEFAULT_FROM_EMAIL = 'xxx'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'



# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bakot',
    'loginsys',
)

MIDDLEWARE_CLASSES = (
    '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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'apifolder.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, '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',
                'django.template.context_processors.media'
            ],
        },
    },
]

WSGI_APPLICATION = 'apifolder.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'xxx',
        'USER': 'xxx',
        'PASSWORD': 'xxx',
        'HOST': 'localhost',
        'PORT': '',
    }
}


LANGUAGE_CODE = 'ru-ru'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = (
)
'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
            os.path.join(BASE_DIR, 'bakot/templates/'),
            os.path.join(BASE_DIR, 'loginsys/templates/'),            
            ]
        ,