0
点赞
收藏
分享

微信扫一扫

Python异常处理TypeError: translation() got an unexpected keyword argument ‘codeset‘

悬灸人雪洋 2024-01-02 阅读 9
djangopython

本篇继续使用投票项目学习,关于投票应用更多内容,请查看

Django创建投票应用-CSDN博客

目录结构
在 polls 目录下创建一个名为 static 的目录。Django 将在该目录下查找静态文件,这种方式和 Diango 在 polls/templates/ 目录下查找 template 的方式类似。

在 polls 文件夹中创建一个名为 style.css 的文件。样式表路径应是 polls/static/polls/style.css。因为 AppDirectoriesFinder 的存在,所以可以在 Django 中以 polls/style.css 的形式引用此文件,类似引用模板路径的方式。

为应用创建样式文件polls/static/polls/style.css

li a {
    color: green;
}

在 polls/templates/polls/index.html 的文件头添加以下内容

{% load static %}

<!DOCTYPE html>

<html lang="zh">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="{% static 'polls/style.css' %}">

</head>

{% static %} 模板标签会生成静态文件的绝对路径。

为应用添加图片
接下来,我们将为图像创建一个子目录。 在 polls/static/polls/ 目录中创建 images 子目录。 在此目录中,添加应用需要的任何图像文件。 如使用一个名为“background.png”的文件,它的完整路径为“polls/static/polls/images/background.png”。

然后,在样式表中添加对图像的引用(polls/static/polls/style.css)

body {
    background: white url("images/background.png") no-repeat;
}

当前项目的目录结构

  • my_site_env (conda环境)
  • mysite (django项目)
    • mysite
    • polls
      • templates
        • polls
      • static
        • polls
          • images

关于在指定位置创建项目环境,更多内容请看

用Anaconda Prompt管理conda环境-CSDN博客

举报

相关推荐

0 条评论