Подключение CSS в Django - Python

Узнай цену своей работы

Формулировка задачи:

Django не отображает таблицы стилей, вот код: views.py
Листинг программы
  1. from django.shortcuts import render_to_response
  2. def translit(request):
  3. return render_to_response('translit.html')
urls.py
Листинг программы
  1. from django.conf.urls import patterns, include, url
  2. from django.conf import settings
  3. from translit.views import translit, dotranslit
  4. # Uncomment the next two lines to enable the admin:
  5. # from django.contrib import admin
  6. # admin.autodiscover()
  7. urlpatterns = patterns('',(r'^translit/$', translit),)
settings.py
Листинг программы
  1. # Django settings for translit project.
  2. from os.path import join, abspath, normpath, dirname
  3. ProjectDir = dirname(abspath(__file__))
  4. def tpl_dir(src):
  5. return normpath(join(ProjectDir, src)).replace('\\', '/')
  6. DEBUG = True
  7. TEMPLATE_DEBUG = DEBUG
  8. ADMINS = (
  9. # ('Your Name', 'your_email@example.com'),
  10. )
  11. MANAGERS = ADMINS
  12. DATABASES = {
  13. 'default': {
  14. 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
  15. 'NAME': '', # Or path to database file if using sqlite3.
  16. 'USER': '', # Not used with sqlite3.
  17. 'PASSWORD': '', # Not used with sqlite3.
  18. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
  19. 'PORT': '', # Set to empty string for default. Not used with sqlite3.
  20. }
  21. }
  22. # Local time zone for this installation. Choices can be found here:
  23. # [url]http://en.wikipedia.org/wiki/List_of_tz_zones_by_name[/url]
  24. # although not all choices may be available on all operating systems.
  25. # In a Windows environment this must be set to your system time zone.
  26. TIME_ZONE = 'America/Chicago'
  27. # Language code for this installation. All choices can be found here:
  28. # [url]http://www.i18nguy.com/unicode/language-identifiers.html[/url]
  29. LANGUAGE_CODE = 'en-us'
  30. SITE_ID = 1
  31. USE_I18N = True
  32. USE_L10N = True
  33. USE_TZ = True
  34. MEDIA_ROOT = ''
  35. MEDIA_URL = ''
  36. STATIC_ROOT = tpl_dir('stats')
  37. STATIC_URL = '/static/'
  38.  
  39. STATICFILES_DIRS = (tpl_dir('stats'), )
  40. STATICFILES_FINDERS = (
  41. 'django.contrib.staticfiles.finders.FileSystemFinder',
  42. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  43. 'django.contrib.staticfiles',
  44. )
  45. SECRET_KEY = '=%ugzer(1^i#u1bfdkp&*a(hsa14gga(%+f1lhii@4xc8_t+lm'
  46. TEMPLATE_LOADERS = (
  47. 'django.template.loaders.filesystem.Loader',
  48. 'django.template.loaders.app_directories.Loader',
  49. )
  50. MIDDLEWARE_CLASSES = (
  51. 'django.middleware.common.CommonMiddleware',
  52. 'django.contrib.sessions.middleware.SessionMiddleware',
  53. 'django.middleware.csrf.CsrfViewMiddleware',
  54. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  55. 'django.contrib.messages.middleware.MessageMiddleware',
  56. )
  57. ROOT_URLCONF = 'translit.urls'
  58. WSGI_APPLICATION = 'translit.wsgi.application'
  59.  
  60. TEMPLATE_DIRS = (tpl_dir('templates'),)
  61. INSTALLED_APPS = (
  62. 'django.contrib.auth',
  63. 'django.contrib.contenttypes',
  64. 'django.contrib.sessions',
  65. 'django.contrib.sites',
  66. 'django.contrib.messages',
  67. 'django.contrib.staticfiles',
  68. )
  69. LOGGING = {
  70. 'version': 1,
  71. 'disable_existing_loggers': False,
  72. 'filters': {
  73. 'require_debug_false': {
  74. '()': 'django.utils.log.RequireDebugFalse'
  75. }
  76. },
  77. 'handlers': {
  78. 'mail_admins': {
  79. 'level': 'ERROR',
  80. 'filters': ['require_debug_false'],
  81. 'class': 'django.utils.log.AdminEmailHandler'
  82. }
  83. },
  84. 'loggers': {
  85. 'django.request': {
  86. 'handlers': ['mail_admins'],
  87. 'level': 'ERROR',
  88. 'propagate': True,
  89. },
  90. }
  91. }
translit.html (шаблон)
Листинг программы
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  5. <meta name="author" content="Eduard" />
  6. <link href="{{STATIC_URL}}css/style.css" rel="stylesheet" type="text/css" media="screen" />
  7. <title>TranslitIt</title>
  8. </head>
  9. <body>
  10. <div id="wrapper">
  11. <div id="logo"></div>
  12. <form name="tranc" id="form" action="/do/" method="get" target="_self">
  13. <label><p>Введите ваш текст на русском:</p>
  14. <p><input name="text" id="text" type="text" size="50"/></p></label>
  15. <p><input name="submit" id="button" type="submit" value="Перевести"/></p>
  16. </form>
  17.  
  18. </div>
  19. </body>
  20. </html>
Таблица стилей находится в папке stats, но ничего не отображается. Помогите разобраться, в чем ошибка?

Решение задачи: «Подключение CSS в Django»

textual
Листинг программы
  1. <!DOCTYPE html>
  2.  
  3. <head>
  4. <!-- используем просто префикс /static/-->
  5.     <link href="/static/css.css" rel="stylesheet" type="text/css" media="screen" />
  6.  
  7.     <title>TranslitIt</title>
  8.        
  9. </head>
  10.  
  11. <body>
  12.     привет
  13.  
  14. </body>
  15. </html>

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

5   голосов , оценка 4.6 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут