如何将Flask的HTML页面更改为Django [英] How to change a html page from flask to Django

查看:79
本文介绍了如何将Flask的HTML页面更改为Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要将Flask模板更改为Django模板的应用程序.如何在html页面中更改url_for('function')

I am working on an app that requires changing a flask template to that of Django.How to change the url_for('function') in the html page

推荐答案

在Django中,您可以使用:

In Django you can use:

{% url 'some-url-name' %}

您还可以如下添加参数:

You can also add params as follows:

{% url 'some-url-name' param1=val1 param2=val2 %}

使用 some-url-name 是您赋予与 view 关联的 url 的名称,如下所示:

With some-url-name is the name that you give to the url associated with your view like the following:

url(r'^some-url/', 'myapp.views.some_view', name='some-url-name')

如果要使用url名称空间,则示例如下所示(我们假设 some-url-name myapp/urls.py 中的url名称):

If you want to use url namespaces, an example looks like this (we suppose some-url-name is the url name in myapp/urls.py):

url(r'^some-url/', include('myapp.urls', namespace='myapp'))

在您的模板中:

{% url 'myapp:some-url-name' param1=val1 param2=val2 %}

与静态文件的某些区别:

在烧瓶中:

url_for('static', filename='path/to/file')

在Django中:

{% static "path/to/file" %}

这篇关于如何将Flask的HTML页面更改为Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆