【发布时间】:2019-04-25 01:28:45
【问题描述】:
大家好,提前感谢您的帮助。
我想在我的 home.html 中引入一个数字,将其保存为变量 'n' 并将其导出到 my_calculations.py 文件中。
<form>
<label for='number'>Number:</label>
<input type='number' value='Save'>
<button type="submit">submit</button>
</form>
你能解释一下我该怎么做吗? 我到处寻找,但有很多关于如何将变量从 .py 发送到模板的信息,但反之则不然。
【问题讨论】:
-
从字面上看,part 4 of the Django tutorial 谈论将表单数据从模板发送到视图。
-
谢谢丹尼尔,现在我想弄清楚如何将 selected_choice 从 views.py... def vote() 导入到 my_file.py。
-
什么是 my_file.py?
-
it
s one file Ive 创建在与视图、模型 ets 相同的级别(我未来的应用程序将需要它)在代码行下的视图中:selected_choice.save() 我添加了:global a, a = selected_choice, print(a) ...但是如何将“a”变量导入 my_file.py? -
但这并没有什么意义。 my_file 中的函数调用是什么?
标签: django python-3.x django-templates