2024-04-25 12:44:17 发布
网友
我正在建立一个网站,其中我的页面是用MediaWiki标记编写的,为此我在Python中有一个有效的解析器函数。在
我到底在哪里解析我的标记:在视图的代码中,还是在模板中?我的第一个猜测是:
return render_to_response( 'blog/post.html', {'post': post, 'content': parseMyMarkup(post.content) })
这是惯例,还是我应该做些不同的事?在
决定是否将代码放在视图或模板中的一般规则是:
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>),那么我会将它放入视图中,因为它将修改您的数据。在
**word** becomes <b>word</b>
希望有帮助!在
决定是否将代码放在视图或模板中的一般规则是:
我不太熟悉标记格式,但是如果您要执行替换(例如:
**word** becomes <b>word</b>
),那么我会将它放入视图中,因为它将修改您的数据。在希望有帮助!在
相关问题 更多 >
编程相关推荐