无法在apache服务器下运行django项目

时间:2018-12-28 11:38:50

标签: django apache django-rest-framework

我已使用pipenv在/ var / www / python3中创建了一个虚拟环境,然后创建了django项目并安装了所有依赖项

我的Pipfile是:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
django = "==2.1.4"
django-rest-swagger = "*"
mysqlclient = "*"
django-cors-headers = "*"
pillow = "*"
djangorestframework = "*"
django-extra-fields = "*"
djangorestframework-xml = "*"
django-filter = "*"

[requires]
python_version = "3.6"

我的wsgi.py文件是:

import os
from django.core.wsgi import get_wsgi_application


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "image_management.settings")

application = get_wsgi_application()

我的urls.py是:

from django.contrib import admin
from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from image_app import views as image_view
from django.urls import path, include
from rest_framework import routers
from django.conf.urls.static import static
from django.conf import settings
from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='Pastebin API')

router = routers.DefaultRouter()
router.register(r'images', image_view.ImageViewSet)
router.register(r'albums', image_view.AlbumViewSet)

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include(router.urls)),
    url(r'^swagger/$', schema_view)
]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

我已经使用来运行我的Apache了:

sudo service apache2 restart

当我尝试使用http://10.75.12.254/admin/访问django的管理页面时 我收到了followinf错误

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.29 (Ubuntu) Server at 10.75.12.254 Port 80

如果打开/var/log/apache2/error.log文件,我将获得以下日志:

[Fri Dec 28 17:05:36.782697 2018] [wsgi:error] [pid 9945:tid 140267535599360] [remote 10.50.10.133:43974] mod_wsgi (pid=9945): Target WSGI script '/var/www/python3/image_management/image_management/wsgi.py' cannot be loaded as Python module.
[Fri Dec 28 17:05:36.782770 2018] [wsgi:error] [pid 9945:tid 140267535599360] [remote 10.50.10.133:43974] mod_wsgi (pid=9945): Exception occurred processing WSGI script '/var/www/python3/image_management/image_management/wsgi.py'.

这是我的000-default.conf:

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html



        <Directory /var/www/python3/image_management/image_management>
                <Files wsgi.py>
                        Order deny,allow
                        Require all granted
                </Files>
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        WSGIDaemonProcess image_management python-path=/var/www/python3/image_management:/home/test/.local/share/virtualenvs/shafiya-YlHOq6Kn/lib/python2.7/site-packages/
        WSGIProcessGroup image_management
        WSGIScriptAlias / /var/www/python3/image_management/image_management/wsgi.py


</VirtualHost>

0 个答案:

没有答案