开发者

Django - markup parser in template or view?

I am building a website where my pages are written in MediaWiki Markup, for which I have a working parser function in Python.

Where exactly do I parse my markup: in the view's code, or in the template? My first guess would be something like:

return render_to_response( 'blog/post.html', {'post': post,
                           'content': parseMyMarku开发者_如何转开发p(post.content) })

Is this the usual convention, or should I do something different?


The general rule for deciding whether or not to place your code in the view or the template is this:

If your code is going to modify the data, put it into the view. If your code will only effect the display of the data, put it into the template.

I'm not very familiar with the markup formatting, but if you are going to be performing substitution (eg: **word** becomes <b>word</b>), then I'd put it into the view as it will be modifying your data.

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜