如何解决Django:具有基于类的视图和明快表格的本地时间表示
我正在用Django建立拍卖网站。用户可能会在不同的时区使用它,因此我决定所有基础日期和时间(例如模型中的datetime值)都将使用UTC。
我使用的是基于类的视图(ListView,DetailView等),并且显示时比较松脆。
在页面上转换为本地时间的最佳策略是什么?我应该在视图中还是在模板中?
解决方法
感谢@Ejaz。我决定反对Moment.js,但这使我朝着正确的方向前进了-我没想到要用Javascript来做。我在基本模板中添加了一个函数,然后从单个模板中调用了它
from tkinter import *
root = Tk()
root.title("Calculator")
ent = Entry(root,width=35,borderwidth=5)
ent.grid(row=0,column=0,columnspan=3,padx=10,pady=10)
def clickButton(number):
current = ent.get()
ent.delete(0,END)
ent.insert(0,str(current) + str(number))
def clearButton():
ent.delete(0,END)
def button_add():
first_number = ent.get()
global f_num
global math
math = "addition"
f_num = int(first_number)
ent.delete(0,END)
def equalButton():
secondNum = ent.get()
ent.delete(0,f_num + int(secondNum))
# this defines the buttons
button1 = Button(root,text="1",padx=40,pady=20,command=lambda: clickButton(1)) # the first button of the calculator
button2 = Button(root,text="2",command=lambda: clickButton(2)) # the second button of the calculator
button3 = Button(root,text="3",command=lambda: clickButton(3)) # the third button of the calculator
button4 = Button(root,text="4",command=lambda: clickButton(4)) # the fourth button of the calculator
button5 = Button(root,text="5",command=lambda: clickButton(5)) # the fifth button of the calculator
button6 = Button(root,text="6",command=lambda: clickButton(6)) # the sixth button of the calculator
button7 = Button(root,text="7",command=lambda: clickButton(7)) # the seventh button of the calculator
button8 = Button(root,text="8",command=lambda: clickButton(8)) # the eighth button of the calculator
button9 = Button(root,text="9",command=lambda: clickButton(9)) # the ninth button of the calculator
button0 = Button(root,text="0",command=lambda: clickButton(0)) # the tenth button of the calculator
button_addition = Button(root,text="+",command=clickButton) # addition button
button_equalSign = Button(root,text="=",padx=91,command=equalButton) # button for the equal sign
button_clr = Button(root,text="C",command=lambda: clearButton()) #button for clearing whatever is written
# this puts the buttons on the screen
#row 3
button1.grid(row=3,column=0)
button2.grid(row=3,column=1)
button3.grid(row=3,column=2)
# row 2
button4.grid(row=2,column=0)
button5.grid(row=2,column=1)
button6.grid(row=2,column=2)
# row 1
button7.grid(row=1,column=0)
button8.grid(row=1,column=1)
button9.grid(row=1,column=2)
# sign buttons
button0.grid(row=4,column=0)
button_clr.grid(row=4,column=1,columnspan=2)
button_addition.grid(row=5,column=0)
button_equalSign.grid(row=5,columnspan=2)
root.mainloop()
def product(fracs):
t = reduce(lambda x,y: x*y,fracs)
return t.numerator,t.denominator
if __name__ == '__main__':
fracs = []
for _ in range(input()):
fracs.append(Fraction(*map(int,input().split())))
result = product(fracs)
print(*result)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。