gpt4 book ai didi

html - Django CSS 附件

转载 作者:行者123 更新时间:2023-11-28 08:10:20 26 4
gpt4 key购买 nike

感谢@Selcuk,通过添加到settings.py STATICFILES_FINDERS & STATICFILES_DIRS 的底部,我现在可以在本地工作了。该页面在本地使用样式表但是一旦我推送到我的 heroku 网络应用程序,它就无法运行样式表。

基本模板代码

<!DOCTYPE html>
<html>
<head>
<title>ToolShare » Mohammad Daraghmeh</title>
<!-- Fav Icon -->
<link rel="shortcut icon" href="http://bit.ly/1xDbduz" type="image/x-icon">
<link rel="icon" href="http://bit.ly/1xDbduz" type="image/x-icon">
<!-- Latest compiled and minified CSS -->
<link href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.4/united/bootstrap.min.css" rel="stylesheet">
<!-- Font-Awesome -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Animate -->
<link href="//cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css" rel="stylesheet">
<!-- Latest jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- Custom Css -->
<link href="{{ STATIC_URL }}css/stylesheet.css" rel="stylesheet" type="text/css">

</head>

settings.py

"""
Django settings for toolshare project.

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/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__))

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_0ut&uh=ou!jdw3e(ys@=x)k_)uu5d-if4ishx8lrjmiu_ma-q'

# 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',
'toolshare',
)

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

ROOT_URLCONF = 'toolshare.urls'

WSGI_APPLICATION = 'toolshare.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/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.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'EST'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'

STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
#"django.contrib.staticfiles.finders.AppDirectoriesFinder"
)

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

CMD的照片CSS 的 304 正常吗,我猜是的,因为它没有被修改。 enter image description here

最佳答案

您的 css 目录位于您的 static 目录下。您应该使用:

<link href="{{ STATIC_URL }}css/stylesheet.css" rel="stylesheet" type="text/css">

或放置

{% load staticfiles %}

在您的 HTML 文件之上,然后使用

<link href="{% static 'css/stylesheet.css' %}" rel="stylesheet" type="text/css">

关于html - Django CSS 附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29306442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com