如何在 Django 1.6 应用程序中实现降价?

2023-11-08Python开发问题
1

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

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11