示例#1
0
def add_twit(request):
    form = TwitForm()
    if request.method == 'POST':
        form = TwitForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('home')
    return render_to_response('add_twit.html', {
        'form': form,
        }, RequestContext(request))
示例#2
0
def edit_twit(request, pk):
    twit = Twit.objects.get(pk=pk)
    form = TwitForm(instance=twit)
    if request.method == 'POST':
        form = TwitForm(request.POST, instance=twit)
        if form.is_valid():
            form.save()
            return redirect('home')
    return render_to_response('add_twit.html', {
        'form': form,
        }, RequestContext(request))