sta*_*r98 5 html python django jquery templates
我已经在 django 项目上工作了几个星期,只是玩玩,以便我能掌握它。我有点困惑。我现在有一个名为“home.html”的模板。我想知道我是否可以将另一个名为“profile.html”的模板设置为 home.html 模板上的链接?我有一个按钮,单击该按钮后,应将我直接带到 profile.html 页面,但是当我对这个主题进行研究时,得到的答案很复杂。有些人表示要创建一个视图并使用 javascript 加载 html,而其他人则表示只需在标签中写入第二页模板的路径会更容易。
完成这项工作的最正确方法是什么?
我查看了这个链接:Rendering another template from a button click in Django to try to get a better understand,因为这是另一个最接近我问的问题,但它让我更加困惑,因为django lingo是作为初学者,我有点难以理解。
预先感谢您提供的任何帮助。
编辑:总而言之:我目前在主页上。有一个按钮,上面写着“查看您的个人资料”。单击该按钮后,我想离开主页并在屏幕上加载新页面“profile.html”。
“最正确的方法”是创建将加载“profile.html”模板的视图。我建议使用通用TemplateView.
将此行添加到您的urls.py:
from django.views.generic import TemplateView
urlpatterns = patterns('',
url(r'^profile/', TemplateView.as_view(template_name='profile.html'),
name='profile'),
)
Run Code Online (Sandbox Code Playgroud)
在home.html中使用以下代码片段:
<a href="{% url 'profile' %}">Profile</a>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6484 次 |
| 最近记录: |