2012-09-13 13 views
5

मैं अपने विकी रूप में HTML टाइप करने से बचने के लिए मार्कडाउन का उपयोग करने का प्रयास कर रहा हूं, लेकिन किसी कारण से फ़ॉर्म इच्छित स्वरूपण के बजाय HTML कोड प्रदर्शित कर रहा है।एचटीएमएल Django टेक्स्ट फ़ील्ड में प्रतिपादन नहीं कर रहा है

from django.shortcuts import render_to_response 
from mywiki.wiki.models import Page 
from django.http import HttpResponseRedirect 
import markdown 


def view_page(request, page_name): 
    try: 
     page = Page.objects.get(pk=page_name) 
    except Page.DoesNotExist: 
     return render_to_response('create.html', {'page_name':page_name}) 

    content = page.content  
    return render_to_response('view.html', {'page_name':page_name, 'content':markdown.markdown(content)}) 

यह मेरा view.html टेम्पलेट है:

मेरा विचार समारोह इस प्रकार है

{% extends 'base.html' %} 
{% load wikilink %} 

{% block title %}{{page_name}}{% endblock %} 

{% block content %} 
     <h1>{{page_name}}</h1> 
     {{content|wikify}} 
     <hr/> 
     <a href='/mywiki/{{page_name}}/edit/'>Edit this page?</a> 

{% endblock %} 

और ये मेरे base.html है:

<html> 
    <head> 
     <title>{{% block title %}{% endblock %}</title> 
    </head> 
    <body> 
<div> 
Menu: <a href='/mywiki/Start/'>Start Page</a> 
</div> 
     {% block content %} 
     {% endblock %} 
    </body> 
</html> 

मैं करता हूँ मार्कडाउन स्थापित है, और मेरा Django संस्करण 1.4.1 (मैक) है।

धन्यवाद।

+0

https://stackoverflow.com/questions/2080559/disable-html-escaping-in-djangos-textfield – ammarx

उत्तर

16

Django के उपयोग safe filter तो अपने एचटीएमएल के लिए के रूप में नहीं भाग निकले किया जाना है।

{{ content|safe }} 
+1

आप फिल्टर श्रृंखला कर सकते हैं? '{{content | wikify | safe}}' –

+2

हां। जहां तक ​​मुझे पता है यह संभव है। – thikonom

+0

हाँ मैं अभी गया और दस्तावेज़ों को देखा और वे आपके साथ सहमत हैं (मेरे से अधिक संक्षिप्त उत्तर के लिए +1: पी) –

1
{% autoescape off %} 
{{content|wikify}} 
{% endautoescape %} 

शायद ...