Django – 解析模板或视图中的标记?

2024-04-25 12:44:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在建立一个网站,其中我的页面是用MediaWiki标记编写的,为此我在Python中有一个有效的解析器函数。在

我到底在哪里解析我的标记:在视图的代码中,还是在模板中?我的第一个猜测是:

return render_to_response( 'blog/post.html', {'post': post,
                           'content': parseMyMarkup(post.content) })

这是惯例,还是我应该做些不同的事?在


Tags: to函数代码标记视图模板解析器return
1条回答
网友
1楼 · 发布于 2024-04-25 12:44:17

决定是否将代码放在视图或模板中的一般规则是:

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.

我不太熟悉标记格式,但是如果您要执行替换(例如:**word** becomes <b>word</b>),那么我会将它放入视图中,因为它将修改您的数据。在

希望有帮助!在

相关问题 更多 >