简体   繁体   English

字符串内的HTML变量

[英]HTML variable inside of String

I'm building a website with Django. 我正在使用Django建立网站。 I want to have a string url [already done], but I want the string to be changeable based on variables. 我想有一个字符串url [已经完成],但是我想根据变量来改变字符串。

sudocode: variable a = "Hello" sudocode:变量a =“ Hello”

url = "www.facebook.com/a" ----> I want the "a" to be changeable, so if it changes, the url goes to a different website. url =“ www.facebook.com/a” ---->我希望“ a”是可更改的,因此,如果更改,URL将转到另一个网站。

What is the best way to do this? 做这个的最好方式是什么?

thanks 谢谢

You should use saving groups in your urls.py : 您应该在urls.py使用保存组

from django.conf.urls import patterns, url

urlpatterns = patterns('',
    url(r'^(?P<part>\w*)/$', 'my_app.views.my_view'),
)

Then, in your my_view view the string will appear as a keyword argument: 然后,在my_view视图中,字符串将作为关键字参数出现:

def my_view(request, part=None):
    print part

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM