当我尝试访问我的Django站点时,我有一个内部服务器错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当我尝试访问我的Django站点时,我有一个内部服务器错误相关的知识,希望对你有一定的参考价值。

我正在尝试使用apache2将服务器ubuntu 18.10推向生产

问题:我只访问我的网站的管理页面和主页,但当我尝试访问博客或像www.mysite.com/blog或www.mysite.com/projects这样的项目“内部服务器错误”时显示器

我的网站的树吼叫

___rp-portfolio
               |
               |___blog
               |
               |___media
               |
               |___personal_portfolio
               |                     |
               |                     |___wsgi.py, settings.py ...
               |
               |
               |___projects
               |
               |__static
               |
               |___venv
               |
               |___db.sqite3
               |
               |___manage.py

下面是apache服务器的.conf

Alias /static /home/username/rp-portfolio/static
  <Directory /home/username/rp-portfolio/static>
    Require all granted
  </Directory>

  Alias /media /home/username/rp-portfolio/media
  <Directory /home/username/rp-portfolio/media>
    Require all granted
  </Directory>

  <Directory /home/username/rp-portfolio/personal_portfolio>
    <Files wsgi.py>
      Require all granted
    </Files>
  </Directory>

  WSGIScriptAlias / /home/username/rp-portfolio/personal_portfolio/wsgi.py
  WSGIDaemonProcess django_app python-path=/home/username/rp-portfolio python-home=/home/username/rp-portfolio/venv
  WSGIProcessGroup django_app 

网站的urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls), #THIS PAGE WORKS
    path('projects/', include("projects.urls")),
    path('', include("blog.urls")),
    path('ckeditor/', include('ckeditor_uploader.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urls.py(博客)

from django.urls import path
from . import views

urlpatterns = [
    path("", views.home, name="home"), #THIS PAGE WORKS
    path("blog/", views.blog_index, name="blog_index"),
    path("blog/<int:pk>/", views.blog_detail, name="blog_detail"),
    path("blog/<category>/", views.blog_category, name="blog_category"),
]

error.log(var / log / apache2 / error.log)我尝试过模板和personal_portfolio / templates

[Sun Apr 14 09:20:34.989828 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418] mod_wsgi (pid=10952): Target WSGI script '/home/saidb/rp-portfolio/personal_portfolio/wsgi.py' cannot be
loaded as Python module.
[Sun Apr 14 09:20:34.989898 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418] mod_wsgi (pid=10952): Exception occurred processing WSGI script '/home/saidb/rp-portfolio/personal_portfo
lio/wsgi.py'.
[Sun Apr 14 09:20:34.990213 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418] Traceback (most recent call last):
[Sun Apr 14 09:20:34.990324 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/home/saidb/rp-portfolio/personal_portfolio/wsgi.py", line 16, in <module>
[Sun Apr 14 09:20:34.990336 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     application = get_wsgi_application()
[Sun Apr 14 09:20:34.990349 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/home/saidb/rp-portfolio/venv/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_w
sgi_application
[Sun Apr 14 09:20:34.990356 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     django.setup(set_prefix=False)
[Sun Apr 14 09:20:34.990368 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/home/saidb/rp-portfolio/venv/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[Sun Apr 14 09:20:34.990374 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Sun Apr 14 09:20:34.990384 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/home/saidb/rp-portfolio/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in _
_getattr__
[Sun Apr 14 09:20:34.990390 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     self._setup(name)
[Sun Apr 14 09:20:34.990399 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/home/saidb/rp-portfolio/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _
setup
[Sun Apr 14 09:20:34.990405 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     self._wrapped = Settings(settings_module)
[Sun Apr 14 09:20:34.990415 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/home/saidb/rp-portfolio/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in
__init__
[Sun Apr 14 09:20:34.990420 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Sun Apr 14 09:20:34.990430 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Sun Apr 14 09:20:34.990436 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     return _bootstrap._gcd_import(name[level:], package, level)
[Sun Apr 14 09:20:34.990446 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Sun Apr 14 09:20:34.990456 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Sun Apr 14 09:20:34.990466 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
[Sun Apr 14 09:20:34.990476 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
[Sun Apr 14 09:20:34.990486 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
[Sun Apr 14 09:20:34.990520 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Sun Apr 14 09:20:34.990531 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]   File "/home/saidb/rp-portfolio/personal_portfolio/settings.py", line 68, in <module>
[Sun Apr 14 09:20:34.990536 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418]     'DIRS': [os.path(BASE_DIR, 'personal_portfolio/templates')],
[Sun Apr 14 09:20:34.990564 2019] [wsgi:error] [pid 10952:tid 140266601051904] [remote 5.51.50.121:63418] TypeError: 'module' object is not callable

views(blog_index)

def blog_index(request):
    posts = Post.objects.all().order_by('-created_on')
    context = {
        "posts": posts,
    }
    return render(request, "blog_index.html", context)


谢谢你的帮助 !!

答案

我喜欢在项目级别创建一个templates文件夹并放入base.html文件。然后在settings.py文件中,更新Django查找模板的位置。添加os.path.join(BASE_DIR, 'templates')。如果这对您有用,请告诉我。

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站点时,我有一个内部服务器错误的主要内容,如果未能解决你的问题,请参考以下文章

错误 Bad Request (400),当我访问域上的站点时

添加负载均衡器时 Django 多租户站点的重定向循环

设置 debug = False 会使 Django 应用程序崩溃并出现以下错误,如何解决?

Jquery mobile 阻止从我的基于 django 的站点下载

如何访问对象内部的数组?

Django Heroku,无法访问此站点,响应时间过长