模板标签未在Apache中加载

时间:2015-12-20 14:53:53

标签: python html django apache django-templates

所以我有一个非常基本的Django应用程序。我已经使用开发服务器部署了应用程序,我的页面似乎完全正常,没有任何打嗝。但是,只要我尝试在Apache服务器上运行它,就会提供HTML页面,但基础模板标签不会。

以下是我的Apache配置:

WSGIScriptAlias / /home/ec2-user/website/bash/wsgi.py
WSGIPythonPath /home/ec2-user/website
<Directory "/home/ec2-user/website/bash/">
    <Files wsgi.py>
            Require all granted
    </Files>
</Directory>

Alias /static/ /home/ec2-user/website/static

<Directory "/home/ec2-user/website/static">
    Require all granted
</Directory>

我唯一使用的模板标签是用于提供静态文件的标签。这是我的settings.py配置:

import os

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

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'landing',
    'home',
)

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',
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'home/','static/'), '/static/')

SITE_MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'home/', 'templates/', 'home')

我知道它没有呈现,因为我在Apache中的访问日志只是显示模板标记的转义字符键值。

[20/Dec/2015:14:00:37 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:00:38 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:05:08 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:05:09 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:19:10 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:19:12 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:25:35 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:25:36 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:25:49 +0000] "GET /%7B%%20static HTTP/1.1" 400 226
[20/Dec/2015:14:25:50 +0000] "GET /%7B%%20static HTTP/1.1" 400 226

这是我的HTML模板代码,请不要介意可怜的代码!

<!DOCTYPE html>
<html>

    <head>
        {% load staticfiles %}

        <title> Home </title>
        <link href="{% static "css/style_file.css" %}" type = "text/css" rel = "stylesheet" />
        <link rel="icon" type="image/png" href="{% static "media/hat.png" %}" />
    </head>

    <body>


        <div class="container">


                <div id="logo"> <img src="{% static "media/title.png" %}" alt="title"></div>
        </div>

    </body>
</html>

我完全迷失了,不知道我哪里出错了。我知道我一般都在为页面提供服务,因为在开发服务器中,视图功能正在按预期提供模板。我在Apache服务器上做错了什么!

编辑:进一步检查,这个问题似乎只存在于端口80上。即使我在该端口上使用开发服务器,它也没有加载相应的标签和/或静态元素。

1 个答案:

答案 0 :(得分:0)

更改了所有权和语法错误的TINIEST。在“/ home / ec2-user / website / static ** / **”之后需要一个尾部斜杠。