我正尝试使用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
观看次数(blog_index)
def blog_index(request):
posts = Post.objects.all().order_by('-created_on')
context = {
"posts": posts,
}
return render(request, "blog_index.html", context)
谢谢您的帮助!
答案 0 :(得分:0)
我喜欢在项目级别创建一个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',
],
},
},
]