管理员文本面板忽略html标签和段落

时间:2016-07-23 19:24:16

标签: django django-admin django-filter

由于某些原因,管理面板中的内容列不会对任何html标记和新段落做出反应。

Here is example of my text in admin panel

This is how it displayed in page

我在models.py中的代码:

# coding: utf-8
from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=255) 
    datetime = models.DateTimeField() 
    content = models.TextField(max_length=10000) 

def __unicode__(self):
    return self.title

def get_absolute_url(self):
    return '/blog/%i/' % self.id

views.py

from django.shortcuts import render
from blog.models import Post
from django.views.generic import ListView, DetailView
from registration.views import RegistrationView
from django.contrib.auth import logout

# Create your views here.

class PostsListView(ListView):
    model = Post                    

class PostDetailView(DetailView):   
    model = Post

def logout_view(request):
    logout(request)

1 个答案:

答案 0 :(得分:1)

默认情况下,管理面板不允许这样做。你需要一个自定义编辑器来做到这一点。 This可能会对您有所帮助。如果您不想安装其他应用,可以通过

包装内容来实现

<p>Some Text</p><p>Some Text</p>

然后使用

{% autoescape off %}{{your.content}}{% endautoescape %}

显示原始HTML内容。

例如

{% autoescape off %}
    <p>Some text </p><p>Some text </p>
{% endautoescape  %}