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 应用程序中实现降价?
基础教程推荐
- 对多索引数据帧的列进行排序 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
