小编Pao*_*olo的帖子

django中的模块化模板

我开始使用Django,我正在尝试制作模块化模板,但我不知道如何.现在,我有以下文件:

1- base.html(提供所有网站的基本布局):

{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title>My site</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/bootsrap.min.css' %}" />
</head>

<body>
<h1>Test title</h1>
{% block content %}
{% endblock %}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

2- index.html(主要数据库读取)

{% extends 'base.html' %}
{% block content %}
{% if latest_smartphones_list %}
<ul>
{% for s in latest_smartphones_list %}
    <li><a href="#">{{ s.brand }} {{ s.name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No smarphones available.</p> …
Run Code Online (Sandbox Code Playgroud)

html python django templates

5
推荐指数
1
解决办法
852
查看次数

获取Django中的所有表数据

我正在尝试通过Django视图访问数据库数据.问题是当我查询它时,它只返回模型上unicode函数的结果.如何访问模型的其他字段?

谢谢!

python django

5
推荐指数
1
解决办法
6937
查看次数

选择字符串的最后一个字符,直到Python中的空格

在Python中有空格之前,有没有有效的方法来选择字符串的最后一个字符?

例如,我有以下字符串:

str = 'Hello my name is John'
Run Code Online (Sandbox Code Playgroud)

我想回"约翰".但如果str是:

str = 'Hello my name is Sally'
Run Code Online (Sandbox Code Playgroud)

我想重新'莎莉'

python string

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×3

django ×2

html ×1

string ×1

templates ×1