Django的新手,我已经尽我所能地使用了所有论坛和教程,但仍无法将表单数据存储到数据库中。我有一个简单的模型,该模型包含一个名称和一个电子邮件字段,最终将在程序中引用该字段。单击提交后,我可以加载不同的页面,但是我的数据不会发布到数据库中。我已经尝试了所有我能想到的东西,因此我的代码可能在这一点上已经过时了,但是在当前迭代中,这就是我所拥有的:
#models.py
from django.db import models
from django.forms import ModelForm
class Patron(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField(max_length=75)
def _unicode_(self):
return self.name
class PatronForm(ModelForm):
class Meta:
model = Patron
#view.py
from django.shortcuts import render_to_response, get_object_or_404
from patrons.models import Patron
from django.template import RequestContext
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.forms import ModelForm
def index(request):
if request.method == 'POST':
post = request.POST
name = post['name']
email = post['email']
f = PatronForm(request.Post)
new_patron = f.save()
return render_to_response('patrons/index.html',
context_instance=RequestContext(request))
#html …Run Code Online (Sandbox Code Playgroud) 我需要能够将 control-c 发送到我启动的新线程。我该怎么办。我可以启动线程,但我需要像在命令行中使用 control-c 那样停止。
from Tkinter import *
import threading # should use the threading module instead!
import Queue
import os
def show1():
os.system('ola_recorder -p MyRecord -i 0')
def show2 ():
os.system('ola_recorder -p MyRecord ')
def stop ():
os.system('^c')
t = threading.Thread(name='Show2', target=show2)
root = Tk()
b = Button(root, text="Show 1", command=lambda: thread.start_new(show1, ()))
b.pack()
b2 = Button(root, text="Show 2", command=lambda: t.start())
b2.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud) python user-interface multithreading tkinter python-multithreading