How do I implement markdown in Django 1.6 app?(如何在 Django 1.6 应用程序中实现降价?)
问题描述
我在 models.py 中有一个文本字段,我可以在其中使用管理员输入博客的文本内容.
I have a text field in models.py where I can input text content for a blog using the admin.
我希望能够以 markdown 格式编写此文本字段的内容,但我使用的是 Django 1.6,并且不再支持 django.contrib.markup.
I want to be able to write the content for this text field in markdown format, but I'm using Django 1.6 and django.contrib.markup is not supported anymore.
我在 Django 1.6 中找不到任何有教程并通过将 markdown 添加到文本字段的地方.有人可以查看我的 .py 文件并帮助我在我的应用中实现降价.
I can't find anywhere that has a tutorial and runs through adding markdown to a text field in Django 1.6. Can someone look at my .py files and help me implement markdown to my app.
from django.db import models
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=200)
pub_date = models.DateTimeField()
text = models.TextField()
tags = models.CharField(max_length=80, blank=True)
published = models.BooleanField(default=True)
admin.py
from django.contrib import admin
from blogengine.models import Post
class PostAdmin(admin.ModelAdmin):
# fields display on change list
list_display = ['title', 'text']
# fields to filter the change list with
save_on_top = True
# fields to search in change list
search_fields = ['title', 'text']
# enable the date drill down on change list
date_hierarchy = 'pub_date'
admin.site.register(Post, PostAdmin)
index.html
<html>
<head>
<title>My Django Blog</title>
</head>
<body>
{% for post in post %}
<h1>{{ post.title }}</h1>
<h3>{{ post.pub_date }}</h3>
{{ post.text }}
{{ post.tags }}
{% endfor %}
</body>
</html>
推荐答案
感谢您的回答和建议,但我决定使用 markdown-deux.
Thank you for your answers and suggestions, but I've decided to use markdown-deux.
我是这样做的:
pip install django-markdown-deux
然后我做了 pip freeze >requirements.txt 以确保我的需求文件已更新.
Then I did pip freeze > requirements.txt to make sure that my requirements file was updated.
然后我将markdown_deux"添加到 INSTALLED_APPS 列表中:
Then I added 'markdown_deux' to the list of INSTALLED_APPS:
INSTALLED_APPS = (
...
'markdown_deux',
...
)
然后我将模板 index.html 更改为:
Then I changed my template index.html to:
{% load markdown_deux_tags %}
<html>
<head>
<title>My Django Blog</title>
</head>
<body>
{% for post in post %}
<h1>{{ post.title }}</h1>
<h3>{{ post.pub_date }}</h3>
{{ post.text|markdown }}
{{ post.tags }}
{% endfor %}
</body>
</html>
这篇关于如何在 Django 1.6 应用程序中实现降价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Django 1.6 应用程序中实现降价?
基础教程推荐
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 包装空间模型 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
