Подключение CSS в Django - Python
Формулировка задачи:
Django не отображает таблицы стилей, вот код:
views.py
urls.py
settings.py
translit.html (шаблон)
Таблица стилей находится в папке stats, но ничего не отображается. Помогите разобраться, в чем ошибка?
Листинг программы
- from django.shortcuts import render_to_response
- def translit(request):
- return render_to_response('translit.html')
Листинг программы
- from django.conf.urls import patterns, include, url
- from django.conf import settings
- from translit.views import translit, dotranslit
- # Uncomment the next two lines to enable the admin:
- # from django.contrib import admin
- # admin.autodiscover()
- urlpatterns = patterns('',(r'^translit/$', translit),)
Листинг программы
- # Django settings for translit project.
- from os.path import join, abspath, normpath, dirname
- ProjectDir = dirname(abspath(__file__))
- def tpl_dir(src):
- return normpath(join(ProjectDir, src)).replace('\\', '/')
- DEBUG = True
- TEMPLATE_DEBUG = DEBUG
- ADMINS = (
- # ('Your Name', 'your_email@example.com'),
- )
- MANAGERS = ADMINS
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': '', # 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:
- # [url]http://en.wikipedia.org/wiki/List_of_tz_zones_by_name[/url]
- # although not all choices may be available on all operating systems.
- # In a Windows environment this must be set to your system time zone.
- TIME_ZONE = 'America/Chicago'
- # Language code for this installation. All choices can be found here:
- # [url]http://www.i18nguy.com/unicode/language-identifiers.html[/url]
- LANGUAGE_CODE = 'en-us'
- SITE_ID = 1
- USE_I18N = True
- USE_L10N = True
- USE_TZ = True
- MEDIA_ROOT = ''
- MEDIA_URL = ''
- STATIC_ROOT = tpl_dir('stats')
- STATIC_URL = '/static/'
- STATICFILES_DIRS = (tpl_dir('stats'), )
- STATICFILES_FINDERS = (
- 'django.contrib.staticfiles.finders.FileSystemFinder',
- 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
- 'django.contrib.staticfiles',
- )
- SECRET_KEY = '=%ugzer(1^i#u1bfdkp&*a(hsa14gga(%+f1lhii@4xc8_t+lm'
- TEMPLATE_LOADERS = (
- 'django.template.loaders.filesystem.Loader',
- 'django.template.loaders.app_directories.Loader',
- )
- 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 = 'translit.urls'
- WSGI_APPLICATION = 'translit.wsgi.application'
- TEMPLATE_DIRS = (tpl_dir('templates'),)
- INSTALLED_APPS = (
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.sites',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- )
- LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': False,
- 'filters': {
- 'require_debug_false': {
- '()': 'django.utils.log.RequireDebugFalse'
- }
- },
- 'handlers': {
- 'mail_admins': {
- 'level': 'ERROR',
- 'filters': ['require_debug_false'],
- 'class': 'django.utils.log.AdminEmailHandler'
- }
- },
- 'loggers': {
- 'django.request': {
- 'handlers': ['mail_admins'],
- 'level': 'ERROR',
- 'propagate': True,
- },
- }
- }
Листинг программы
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
- <meta name="author" content="Eduard" />
- <link href="{{STATIC_URL}}css/style.css" rel="stylesheet" type="text/css" media="screen" />
- <title>TranslitIt</title>
- </head>
- <body>
- <div id="wrapper">
- <div id="logo"></div>
- <form name="tranc" id="form" action="/do/" method="get" target="_self">
- <label><p>Введите ваш текст на русском:</p>
- <p><input name="text" id="text" type="text" size="50"/></p></label>
- <p><input name="submit" id="button" type="submit" value="Перевести"/></p>
- </form>
- </div>
- </body>
- </html>
Решение задачи: «Подключение CSS в Django»
textual
Листинг программы
- <!DOCTYPE html>
- <head>
- <!-- используем просто префикс /static/-->
- <link href="/static/css.css" rel="stylesheet" type="text/css" media="screen" />
- <title>TranslitIt</title>
- </head>
- <body>
- привет
- </body>
- </html>
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д