포트폴리오를 만들고 로컬로 테스트하려고하지만 미디어 컨텐츠를 사용하지 않습니다. 실제로 많은 노력을했습니다. 아이디어가 없습니다.미디어 컨텐츠 작동
W3C 유효성 검사기를 사용했기 때문에 생성 된 HTML이 정확합니다. /media/css/foo.css
그리고 내 settings.py 내 MEDIA_URL도 corrent입니다 확신 해요 : 그리고 SRC가가 참조 또한 올바른 지금 여기
/media/
을 내 settingsfile, HTML, CSS, 뷰, URL 및 filestructure
설정 :
# Django settings for portfolio project.
import os
gettext = lambda s: s
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.join(PROJECT_PATH, 'database.db'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join(PROJECT_PATH, "media")
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = "/media/"
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'blabla'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS= (
'django.core.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'portfolio_svn.urls'
LANGUAGES = [
('en', 'English'),
]
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_PATH, "templates"),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'portfolio',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
HTML : base.html
,691,363 (210 개)<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>{% block page_title %}{% endblock %}</title>
<link rel="stylesheet" href="{{ MEDIA_URL }}base.css" />
{% block head_extra %} {% endblock %}
<!-- Enabling HTML5 tags for older IE browsers -->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<header>
<h1>My portfolio</h1>
</header>
{% block nav %}
<nav id = "navigation">
</nav>
{% endblock %}
<section id = "content">
{% block content %}
{% endblock %}
</section>
<footer>
</footer>
{% block includes %}{% endblock %}
</body>
</html>
HTML index.html을
{% extends "portfolio/base.html" %}
{% block page_title %}
Lime Design | Best web dev and design online
{% endblock %}
{% block head_extra %}
<link rel="stylesheet" href="{{ MEDIA_URL }}css/nav_port.css" />
{% endblock %}
{% block content %}
<nav id = "filter">
</nav>
<section id="container">
<ul id="stage">
{% for project in projecten %}
<li data-tags="{{ project.disciplines }}">
<img src="{{ project.overview_image }}" alt="{{ project.name }}" />
</li>
{% endfor %}
</ul>
</section>
{% endblock %}
{% block includes %}
<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src = "{{ MEDIA_URL }}js/jquery.quicksand.js"></script>
<script src = "{{ MEDIA_URL }}js/script.js"></script>
{% endblock %}
CSS
body{
background-color: #151515;
}
보기
from django.shortcuts import get_object_or_404, render_to_response
from django.template.context import RequestContext
from django.http import HttpResponseRedirect, HttpResponse, Http404
from models import Medium, Client, Project
def index(request):
projecten = Project.objects.all()
context = {'projecten': projecten}
return render_to_response('portfolio/index.html', context_instance=RequestContext(request, context))
URL이 :
from django.conf.urls.defaults import *
from portfolio_svn.portfolio.models import Project
from portfolio_svn.portfolio.views import index
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^index', index),
(r'^', index),
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
)
파일 구조
그래서 정적 폴더 (다른 정적 폴더를 넣어야합니다.)를 넣어야합니다. 다른 응용 프로그램 폴더 ..? 그거 조금 .. 음, '이상한'아닌가요? /media/CSS-or-JS-or-.../files-or-subdirsforapps를 만드는 것이 더 자연스럽지 않습니까? collectstatic을 수행 할 때 'unknown command'collectstatic 'type manage.py help '사용에 대해 –
오 확인하지 않았다면 collectstatic에 대한 정적 응용 프로그램을 설치해야합니다. 그리고 네, 당신의 관점을 이해합니다. 앱에 해당 폴더를 가지고있는 것이 좋은 점은 그 앱을 다른 프로젝트에 전달할 때 그곳으로 옮기고 settings.py에 설치하기 만하면된다는 것입니다. – Hassek
: 정적 시스템을 설정하려면 http://blog.bixly.com/post/4579203162/django-static-files + http://django-staticfiles.readthedocs.org/en/latest/#staticfiles-dirs) 그러나 지금은 예를 들어, 내가 (findstatic nav_port.css를 사용했을 때, "No matching files found for ..."이 발견되었습니다. 그곳에 있다는 것을 알기 때문에 이상합니다. –