我的静态文件没有显示,我无法弄清楚原因。以下是我的目录:
- mb <app_name>
-src
-mb
-static
- static_dirs
- static_root
-templates
我的settings.py文件看起来像这样:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# print "This is base ", BASE_DIR
DEBUG_CONST = True
# SECURITY WARNING: don't run with debug turned on in production!
TEMPLATE_DEBUG = DEBUG_CONST
DEGUB = DEBUG_CONST
ALLOWED_HOSTS = ['*']
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'mb.context_processors.init',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
],
},
},
]
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static", "static_dirs"),
)
STATIC_ROOT = os.path.join(BASE_DIR, "static", "static_root")
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media_root')
我的网址:
from django.conf.urls import include, url, patterns
from django.conf.urls.static import static
urlpatterns = patterns(
'',
url(r'^$', 'mb.views.login_view', name='login'),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
在我的基本模板中,我有这个代码段:
{% load staticfiles %}
<!doctype>
<html>
<head>
<title>MB</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
<link href='https://fonts.googleapis.com/css?family=Ceviche+One' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Arimo' rel='stylesheet' type='text/css'>
<!-- bxSlider CSS file -->
<link href="{% static 'js/lib/jquery.bxslider/jquery.bxslider.css' %}" rel="stylesheet"/>
</head>
这是我的观点:
from django.shortcuts import render, render_to_response
from django.template.context_processors import csrf
def login_view(request):
# c = get_base_context(request)
c = {}
c.update(csrf(request))
return render_to_response('download.html', c)
这是我的错误日志告诉我的:
Exception while resolving variable 'request' in template 'download.html'.
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/template/base.py", line 905, in _resolve_lookup
(bit, current)) # missing attribute
VariableDoesNotExist: Failed lookup for key [request] in u'[{\'False\': False, \'None\': None, \'True\': True}, {u\'csrf_token\': <SimpleLazyObject: u\'WOTjM9l9i0UAGyzVE2K039tkteP3Z0nk\'>}, {\'block\': <Block Node: content. Contents: [<TextNode: u\'\\n<style type="text/css">\\n\'>, <django.template.defaulttags.URLNode object at 0x1111b7910>, <TextNode: u\'" style="color:white">ABO\'>, <django.contrib.staticfiles.templatetags.staticfiles.StaticFilesNode object at 0x1111b79d0>, <TextNode: u\'" alt="" height="600" sty\'>, <django.contrib.staticfiles.templatetags.staticfiles.StaticFilesNode object at 0x1111b7a90>, <TextNode: u\'" alt="" class="third_ima\'>, <django.contrib.staticfiles.templatetags.staticfiles.StaticFilesNode object at 0x1111b7b50>, <TextNode: u\'" type="video/mp4"/>\\n \'>, <django.contrib.staticfiles.templatetags.staticfiles.StaticFilesNode object at 0x1111b7c10>, <TextNode: u\'" type="video/mp4"/>\\n \'>, <django.contrib.staticfiles.templatetags.staticfiles.StaticFilesNode object at 0x1111b7cd0>, <TextNode: u\'" type="video/ogg"></sour\'>, <TextNode: u\'" ng-submit="preregister_\'>, <django.template.defaulttags.CsrfTokenNode object at 0x1111b7d50>, <TextNode: u\'\\n\\t \'>, <django.template.defaulttags.URLNode object at 0x1111b7e10>, <TextNode: u\'" class="text-sm">Forgot \'>, <TextNode: u\'?next=\'>, <Variable Node: request.path>, <TextNode: u\'" type="submit" class="bt\'>]>}]'
Not Found: /static/css/main.css
Not Found: /static/js/lib/jquery.bxslider/jquery.bxslider.css
Not Found: /static/js/require.js
Not Found: /static/img/iphone-frame.png
Not Found: /static/img/guy_with_box.png
Not Found: /static/video/featured_video.mp4
Not Found: /static/js/require.js
Not Found: /static/video/featured_video.mov
我已经尝试将我的django降级到1.8,这似乎不起作用,我也尝试将静态文件夹放在不同的路径中并在settings.py中链接到它并且没有任何效果。我的模板显示得很好,这让它更加混乱。