2011-08-06 4 views
1

포트폴리오를 만들고 로컬로 테스트하려고하지만 미디어 컨텐츠를 사용하지 않습니다. 실제로 많은 노력을했습니다. 아이디어가 없습니다.미디어 컨텐츠 작동

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

파일 구조

답변

3

당신은 정적가 무엇인지에 대한 미디어를 사용하는 것 나는 누군가가 나에게 핀 포인트 문제를 도울 수 있기를 바랍니다

portfolio_svn 
├── database.db 
├── __init__.py 
├── __init__.pyc 
├── local_settings.py 
├── local_settings.pyc 
├── manage.py 
├── media 
│ ├── css 
│ │ └── nav_port.css 
│ ├── images 
│ │ └── thumbmails 
│ │  ├── 1.png 
│ │  ├── 2.png 
│ │  ├── 3.png 
│ │  └── 4.png 
│ └── js 
│  ├── jquery.quicksand.js 
│  └── script.js 
├── portfolio 
│ ├── admin.py 
│ ├── admin.pyc 
│ ├── __init__.py 
│ ├── __init__.pyc 
│ ├── models.py 
│ ├── models.pyc 
│ ├── tests.py 
│ ├── views.py 
│ └── views.pyc 
├── settings_backup_local.py 
├── settings_backup_real.py 
├── settings.py 
├── settings.pyc 
├── templates 
│ └── portfolio 
│  ├── base.html 
│  └── index.html 
├── urls.py 
└── urls.pyc 

.. 이력서에 here

을 확인 , 미디어 폴더는 사진, 파일 등을 업로드하는 사람들을 위해 만들어졌습니다.

정적 폴더는 웹 사이트에서 사용하는 css, js 이미지 용입니다. 별도의 서버에 정적 폴더를로드하지 않는 경우

당신은 당신의 urls.py

from django.contrib.staticfiles.urls import staticfiles_urlpatterns 

urlpatters = patterns ......#do your patterns here 

urlpatterns += staticfiles_urlpatterns() 

장고 바로 정적 파일을 마운트하는 방법이 라인을 추가 할 수 있습니다. 장고는이 값을 당신의 settings.py에 추가한다이 정적 파일을 찾을 수있게하기 위해

: 수입 운영 체제를

PROJECT_ROOT = os.path.dirname(__file__) 

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static/') 

STATIC_URL = '/static/' 

STATICFILES_DIR = (
    "portfolio/static/", 
) 

STATICFILES_FINDERS = ( 
'django.contrib.staticfiles.finders.FileSystemFinder', 
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
#'django.contrib.staticfiles.finders.DefaultStorageFinder', 
) 

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.static', 
    #... other context processors 
) 

INSTALLED_APPS = (
    ....#other apps 
    'django.contrib.staticfiles', 
) 

이동을하는 (이 경우 포트폴리오) 앱 aplication 정적 폴더

./manage.py collectstatic. 

내가 제대로 작동하는지 확인해보십시오. ('django.core.context_processors.static'btw에 대한 'django.core.context_processors.media'를 변경해야합니다)

P.D.: render_to_response에 요청을 전달하려면 대신 render (request, 'portfolio/index.html')를 사용할 수 있습니다 :)

+0

그래서 정적 폴더 (다른 정적 폴더를 넣어야합니다.)를 넣어야합니다. 다른 응용 프로그램 폴더 ..? 그거 조금 .. 음, '이상한'아닌가요? /media/CSS-or-JS-or-.../files-or-subdirsforapps를 만드는 것이 더 자연스럽지 않습니까? collectstatic을 수행 할 때 'unknown command'collectstatic 'type manage.py help '사용에 대해 –

+0

오 확인하지 않았다면 collectstatic에 대한 정적 응용 프로그램을 설치해야합니다. 그리고 네, 당신의 관점을 이해합니다. 앱에 해당 폴더를 가지고있는 것이 좋은 점은 그 앱을 다른 프로젝트에 전달할 때 그곳으로 옮기고 settings.py에 설치하기 만하면된다는 것입니다. – Hassek

+0

: 정적 시스템을 설정하려면 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 ..."이 발견되었습니다. 그곳에 있다는 것을 알기 때문에 이상합니다. –