如何将用户在模板中输入的值作为django中的参数传递给函数?
我想获取用户给定的输入值,即本例中的评级,并想调用指定的函数,但该函数不返回任何内容。因此,我想在单击“提交”后保持在同一页面中 这是详细信息页面的代码如何将用户在模板中输入的值作为django中的参数传递给函数?,django,forms,django-forms,django-templates,django-views,Django,Forms,Django Forms,Django Templates,Django Views,我想获取用户给定的输入值,即本例中的评级,并想调用指定的函数,但该函数不返回任何内容。因此,我想在单击“提交”后保持在同一页面中 这是详细信息页面的代码 <h4>Hai this is the details page for the movies {{ plot }}</h4> <form action="#" method="post"> {% csrf_token %} Ratings: <input type="number" na
<h4>Hai this is the details page for the movies {{ plot }}</h4>
<form action="#" method="post">
{% csrf_token %}
Ratings: <input type="number" name="quantity" step="0.5" min="1" max="5"><br>
<input type="submit" value="Click">
</form>
Hai这是电影{{plot}的详细页面
{%csrf_令牌%}
评级:
这是我需要通过传递用户给定的值来调用的函数,该函数不返回任何内容,而是将值存储到csv文件中
def rate_movie(user_id , movie_id , rating_value):
pc = ratings.movie_id[ratings.user_id == user_id] # gets all the movies rated by this user
ad = pc.tolist() #converts to list
s = 0
# This loop finds the exact location in the table to store the rating.
for p in ad:
if movie_id < p:
s = ad.index(p)
break
#Splits the table at this point.
seperate = list(pc[pc == s].index)[0]
#The row which will be added to the table.
bla = [user_id,movie_id,rating_value,665345]
#Splitting the table
pq = ratings[:seperate+1]
rs = ratings[seperate+1:len(ratings)]
pq.loc[len(pq)] = bla
pq.index = pq.index + 1
pq = pq.append(rs , ignore_index=True)
pq.to_csv("/home/iffu/Documents/ratingsss.csv",index = False)
def rate_movie(用户id、电影id、分级值):
pc=ratings.movie_id[ratings.user_id==user_id]#获取此用户对所有电影进行评级
ad=pc.tolist()#转换为列表
s=0
#此循环在表中查找存储评级的确切位置。
对于ad中的p:
如果电影id
好吧,看起来你对应该有用的东西有点困惑。首先,我看到您使用动词GET而不是POST来传递值,这是非常不安全的。然后你应该阅读python的禅宗(变量pq,bla,s,pc是什么意思?)请明确一点!而不是保存到csv中,为什么不放一个返回语句?看起来你在某个地方复制了代码,却不知道自己在做什么。。。但也许我错了。现在我已经更改了get to post…嗯,看起来你对的东西应该有用有些困惑。首先,我看到您使用动词GET而不是POST来传递值,这是非常不安全的。然后你应该阅读python的禅宗(变量pq,bla,s,pc是什么意思?)请明确一点!而不是保存到csv中,为什么不放一个返回语句?看起来你在某个地方复制了代码,却不知道自己在做什么。。。但也许我错了。现在我已经改变了“获取到”帖子。。