apache-django不提供css文件

时间:2014-12-14 08:35:36

标签: python django apache

我想在Ubuntu 13.10上使用Apache 2.4和mod_wsgi配置和运行Django。 一切都有效,除了CSS。我究竟做错了什么?

我通过https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/创建了我的/etc/apache2/sites-available/mysite.conf文件

WSGIScriptAlias / /home/evgeny/django_progects/django_show_table/table/wsgi.py
WSGIPythonPath /home/evgeny/django_progects/django_show_table

Alias /static/ /home/evgeny/django_progects/django_show_table/static/

<Directory home/evgeny/django_progects/django_show_table/static>
Require all granted
</Directory>

<Directory /home/evgeny/django_progects/django_show_table/table>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

settings.py

2   Django settings for table project.
3   
4   For more information on this file, see
5   https://docs.djangoproject.com/en/1.7/topics/settings/
6   
7   For the full list of settings and their values, see
8   https://docs.djangoproject.com/en/1.7/ref/settings/
9   """
10  
11  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12  import os
13  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14  
15  TEMPLATE_CONTEXT_PROCESSORS =(
16      "django.contrib.auth.context_processors.auth",
17      "django.core.context_processors.debug",
18      "django.core.context_processors.i18n",
19      "django.core.context_processors.media",
20      "django.core.context_processors.static",
21      "django.core.context_processors.tz",
22      "django.contrib.messages.context_processors.messages",
23      "django.core.context_processors.request",
24  )
25  
26  TEMPLATE_DIRS = (
27      os.path.join(BASE_DIR, 'templates'),
28      os.path.join(BASE_DIR, '/loginsys/templates'),
29      os.path.join(BASE_DIR, '/table_view/templates'),
30  )
31  
32  # Quick-start development settings - unsuitable for production
33  # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
34  
35  # SECURITY WARNING: keep the secret key used in production secret!
36  SECRET_KEY = 'eszu&dq85t6zzd&1+e7a!5mbi*0em+%cev8_zntm3v5u6o+@zt'
37  
38  # SECURITY WARNING: don't run with debug turned on in production!
39  DEBUG = True
40  
41  TEMPLATE_DEBUG = True
42  
43  ALLOWED_HOSTS = []
44  
45  
46  # Application definition
47  
48  INSTALLED_APPS = (
49      'django.contrib.admin',
50      'django.contrib.auth',
51      'django.contrib.contenttypes',
52      'django.contrib.sessions',
53      'django.contrib.messages',
54      'django.contrib.staticfiles',
55      'table_view',
56     
57      'loginsys',
58  )
59  
60  MIDDLEWARE_CLASSES = (
61      'django.contrib.sessions.middleware.SessionMiddleware',
62      'django.middleware.common.CommonMiddleware',
63      'django.middleware.csrf.CsrfViewMiddleware',
64      'django.contrib.auth.middleware.AuthenticationMiddleware',
65      'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
66      'django.contrib.messages.middleware.MessageMiddleware',
67      'django.middleware.clickjacking.XFrameOptionsMiddleware',
68  )
69  
70  ROOT_URLCONF = 'table.urls'
71  
72  WSGI_APPLICATION = 'table.wsgi.application'
73  
74  
75  # Database
76  # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
77  
78  DATABASES = {
79      'default': {
80          'ENGINE': 'django.db.backends.sqlite3',
81          'NAME': os.path.join(BASE_DIR, 'book_db.sqlite3'),
82      }
83  }
84  
85  # Internationalization
86  # https://docs.djangoproject.com/en/1.7/topics/i18n/
87  
88  LANGUAGE_CODE = 'en-us'
89  
90  TIME_ZONE = 'UTC'
91  
92  USE_I18N = True
93  
94  USE_L10N = True
95  
96  USE_TZ = True
97  
98  
99  # Static files (CSS, JavaScript, Images)
100 # https://docs.djangoproject.com/en/1.7/howto/static-files/
101 
102 STATIC_URL = '/static/'
103 
104 STATICFILES_DIRS = (
105     ('static', os.path.join(BASE_DIR, 'static')),
106 )

1 个答案:

答案 0 :(得分:0)

运行

python manage.py collectstatic 

将静态文件收集到STATIC_ROOT中,然后由apache提供服务。