1
我使用Flask編寫Web應用程序,我想知道使用url_for
在模板和應用程序代碼中生成鏈接的原因。爲什麼使用`url_for`?
我該怎麼做這個增益:
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
這:
<ul>
<li><a href="{{ url_for('index') }}">Home</a></li>
<li><a href="{{ url_for('about') }}">About Us</a></li>
<li><a href="{{ url_for('contact') }}">Contact</a></li>
</ul>
而不是硬編碼的路徑?