2015-04-02 44 views
0

我一直在尝试部署静态.css文件和网站的东西,我的同学和我一直在做。现在我们有一些垃圾样式和东西,所以我们决定使用Bootstrap中的一些代码来使它看起来不错。如何使用Django部署静态文件

编辑我的settings.py并执行python manage.py collectstatic后,静态文件被放入静态/文件夹中。在使用runserver命令时,没有任何样式更改。我一直在谷歌上看了一段时间,但我还没有找到解决方案。

我想让它在我的本地机器上工作,然后将其推送到PythonAnywhere。

任何帮助将不胜感激。

这里是我的settings.py文件

""" 
Django settings for Dreadnaught project. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.7/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/1.7/ref/settings/ 
""" 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
import os 
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = GOTCHA! 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

TEMPLATE_DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = (
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'TTT' 
) 

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
) 

ROOT_URLCONF = 'Dreadnaught.urls' 

WSGI_APPLICATION = 'Dreadnaught.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', 
     'NAME': 'Dreadnaught', 
     'USER': 'root', 
     'PASSWORD': 'root', 
     'HOST': '', 
     'PORT': '', 
    } 
} 

# Internationalization 
# https://docs.djangoproject.com/en/1.7/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.7/howto/static-files/ 

STATIC_URL = '/static/' 

STATIC_PATH = os.path.join(BASE_DIR, 'static') 

STATIC_ROOT = os.path.join(BASE_DIR, 'static') 

STATICFILES_DIRS =() 

TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates') 

TEMPLATE_DIRS = (TEMPLATE_PATH,) 
+0

这里有一个[指南,如何获得与pythonanywhere Django的工作静态文件(https://www.pythonanywhere.com/wiki/DjangoStaticFiles) – hwjp 2015-04-03 12:58:13

回答

0

如果你想为你的CSS和生产模式js文件必须更改调试时真亦假。

DEBUG=False

仅供参考STATIC

+0

我改变了DEBUG为False并将本地主机添加到我的ALLOWED_HOSTS。我仍然没有得到更新的样式。 – DrZoo 2015-04-02 03:57:32

+0

@DrZoo更改回DEBUG = TRUE。首先在上面设置正确,然后您可以通过http:// localhost:8000/static/css/bootstrap.min.css访问浏览器中的静态文件。那是行得通吗? – 2015-04-02 04:41:17

+0

不,这是否意味着我错过了那个文件?如果是这样,那么文件包含了什么?错误是:请求方法:\t GET 请求URL:\t http:// localhost:8000/static/css/bootstrap.min.css 'css/bootstrap.min.css'找不到 – DrZoo 2015-04-02 04:47:23

相关问题