css没有加载到我的登录和管理页面在django [英] css not loading in my login and admin page in django

查看:81
本文介绍了css没有加载到我的登录和管理页面在django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在django中是新手,我正式开始学习django。



我使用django在virtualenv旁边,但是我有一个
的问题登录页面和管理页面因为



他们没有加载css并显示登录
页面和没有任何样式的管理页面

 
Django设置为mysite项目

使用Django 1.8.1生成'django-admin startproject'。

有关此文件的更多信息,请参阅
https://docs.djangoproject.com/en/1.8/topics/settings/

有关完整列表的设置及其值,请参阅
https://docs.djangoproject.com/en/1.8/ref/settings/


#在项目中构建路径像这样:os.path.join(BASE_DIR,...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__ ))


#快速启动开发设置 - 不适合生产
#请参阅https://docs.djangoproject.com/en/1.8/howto / deployment / checklist /

#安全警告:保留生产密钥中使用的密钥!
SECRET_KEY ='g8%o @ ackd!hzekoho4rn7r7-t_m!sk $ * nwi-4j556t =!ln3(@ +'

#安全警告:不要运行调试打开在生产!
DEBUG = True

ALLOWED_HOSTS = []


#应用程序定义

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


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',
'django.middleware.security.SecurityMiddleware',


ROOT_URLCONF ='mysite.urls'

TEMPLATES = [
{
'BACKEND':'django.template.backends.django.DjangoTemplates',
'DIRS':[],
'APP_DIRS':True,
'选项':{
'context_processors':[
'django.template.context_processors.debug',
'django.template.context_processors.request',
' django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION ='mysite.wsgi.application'


#数据库
#https://docs.djangoproject.com/en/1.8/ ref / settings /#databases

DATABASES = {
'default':{
'ENGIN E':'django.db.backends.sqlite3',
'NAME':os.path.join(BASE_DIR,'db.sqlite3'),
}
}


#国际化
#https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE ='en-us'

TIME_ZONE ='UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


#静态文件(CSS,JavaScript,图像)
#https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL ='/ static /'


解决方案

首先,创建文件夹命名为static,那么您需要将所有css / js文件复制到项目中的静态文件夹中(或创建静态文件夹的任何位置)。然后在 settings.py 中声明静态文件目录路径

  STATIC_URL ='/ static /'
STATICFILES_DIRS =('assets',BASE_DIR +'/ static /',)

在您的html文件中,添加以下行 -
{%load staticfiles%}
在标题部分或顶部的文件。

< head> 部分中,您可以使用以下代码链接css / js文件

 < link rel =stylesheethref ={%static'assets / css / mystyle.css'%}> 
< / link>
< script src ={%static'assets / js / jquery.js'%}>< / script>


I'm newbie in django and I started learning django with official tutorial.

I use django beside virtualenv, but I have a problem with the login page and admin page because

they aren't load css and show login page and admin page without any style

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 1.8.1.

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

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

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

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'g8%o@ackd!hzekoho4rn7r7-t_m!sk$*nwi-4j556t=!ln3(@+'

# SECURITY WARNING: don't run with debug turned on in production!
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',
    'polls',
)

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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/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.8/howto/static-files/

STATIC_URL = '/static/'

解决方案

First of all, Create folder named as "static", then you need to copy all the css/js file into static folder inside your project(or wherever you create static folder). Then declare the static files directory path in your settings.py

STATIC_URL = '/static/'
STATICFILES_DIRS = ('assets', BASE_DIR +'/static/',)

In your html file, add following line -
{% load staticfiles %}
at top of the header section or top of the file.
In <head> section you can link the css/js file using following code

<link rel="stylesheet" href="{% static 'assets/css/mystyle.css'%}">
</link>
<script src="{% static 'assets/js/jquery.js'%}"></script>

这篇关于css没有加载到我的登录和管理页面在django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆