Django中调用base.html的功能是什么,如何在base.html中执行python代码,在运行时执行 [英] What is the function in Django that calls base.html and how can I see python code inside base.html execute at runtime

查看:651
本文介绍了Django中调用base.html的功能是什么,如何在base.html中执行python代码,在运行时执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道它的2个问题,但我需要看到我的python代码的值在运行时执行。任何人都可以告诉我这是如何工作的? python是否在客户端执行,如果是这样,我可以如何看到它的值可以在Eclipse中的我的视图类?
我想我正在调用一个js函数,显示一个带有自定义python的calandar,但我不知道它在哪里,所以我可以调试它。这是对base.html中的js的调用

 < script src =$ {url_static} js / jquery.ui .datepicker-ja.jstype =text / javascript>< / script> 
< script src =$ {url_static} js / admin / jquery-ui.min.jstype =text / javascript>< / script>

< script type =text / javascript>
$(function(){$('。datepicker')。datepicker();});
< / script>


解决方案

Python代码在服务器上执行。生成的html被发送到客户端。在你发布的代码中,{url_static}是被替换为实际的值,但可能不起作用,因为django模板寻找变量为 {{url_static}} 。注意双括号。



由于jquery未加载,您的datepicker不起作用。您可以查看渲染页面的源(或检查元素),并确认脚本src是否正确。


I'm not sure if its 2 questions, but I need to see the values of my python code being executed at runtime. Can anyone tell me how this works? Does the python get executed on the client side, and if so, how can I see its values like I can for my views classes in Eclipse? I think I'm calling a js function that shows a calandar with custom python, but I'm not sure where it is so I can debug it. this is the call to the js in base.html

<script src="${url_static}js/jquery.ui.datepicker-ja.js" type="text/javascript"></script>
<script src="${url_static}js/admin/jquery-ui.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function(){$('.datepicker').datepicker();});
    </script>

解决方案

Python code is executed on the server. The generated html is sent to the client. In the code you have posted {url_static} is meant to be replaced with the actual value, but probably doesn't work since django template looks for variables as {{ url_static }}. Notice the double braces.

Your datepicker isn't working since jquery isn't loaded. You can view source (or inspect element) for your rendered page and confirm if the script src is correct.

这篇关于Django中调用base.html的功能是什么,如何在base.html中执行python代码,在运行时执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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