我在 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)
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)
<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 应用程序中实现降价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!