Ejemplo n.º 1
0
def moments_input(request):
    # render(requtest, 'app/test.html')
    if request.method == 'POST':
        form = MomentForm(request.POST)
        if form.is_valid():
            moment = form.save()
            moment.save()
            return HttpResponseRedirect(reverse("app:welcome"))
    else:
        form = MomentForm()
    return render(request, 'app/moments_input.html', {'form': form})
Ejemplo n.º 2
0
def moments_input(request):
    if request.method=='POST':
        form=MomentForm(request.POST)
        if form.is_valid():
            moment=form.save()
            moment.save()
            return HttpResponseRedirect(reverse("app.views.welcome"))
    else:
        form=MomentForm()
    PROJECT_ROOT=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    return render(request,os.path.join(PROJECT_ROOT,'app/templates','moments_input.html'),{'form':form})
Ejemplo n.º 3
0
def moments_input(request):
    if request.method == 'POST':
        form = MomentForm(request.POST)
        if form.is_valid():
            moment = form.save()
            moment.save()
            return HttpResponseRedirect(reverse("app.views.hello"))
    else:
        form = MomentForm()
        args = {}
        args['form'] = form
    return render_to_response('moments_input.html', args)
Ejemplo n.º 4
0
def welcom(request):
    if request.method =="POST":
        form =MomentForm(request.POST)
        if  form.is_valid() :
            moment =form.save()
            moment.save()
            return HttpResponseRedirect(reverse("app.view.welcome"))
    else:
        form =MomentForm()
    PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    print PROJECT_ROOT
    return render(request, os.path.join(PROJECT_ROOT, 'app/templates', 'moments_input.html'), {'form': form})  
Ejemplo n.º 5
0
def moment_input(request):
    if request.method == 'POST':  #用户提交POST表单,则保存moment对象,并重定向到欢迎页面
        form = MomentForm(request.POST)
        if form.is_valid():
            moment = form.save()
            moment.save()
            return HttpResponseRedirect('/app/show')
    else:  #否则返回模板渲染结果作为HTTP Response
        form = MomentForm()
    PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    return render(
        request,
        os.path.join(PROJECT_ROOT, 'app/templates', 'moments_input.html'),
        {'form': form})
Ejemplo n.º 6
0
def moments_input(request):
    data = {'content': '请填写内容', 'user_name': '匿名'}
    if request.method == 'POST':
        form = MomentForm(request.POST, initial=data)
        if form.is_valid():
            moment = form.save()
            moment.save()
            return HttpResponseRedirect(reverse("app.views.welcome"))
    else:
        form = MomentForm()
    import os
    PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    print(PROJECT_ROOT)
    return render(
        request,
        os.path.join(PROJECT_ROOT, 'app/templates', 'moments_input.html'),
        {'form': form})
Ejemplo n.º 7
0
def moments_input(request):
    if request.method == 'POST':
        data = {
            'content': 'Please input the content',
            'user_name': '匿名',
            'kind': 'Python技术',
        }
        form = MomentForm(request.POST, initial=data)
        if form.has_changed():
            print('如下字段进行了修改:')
            for field in form.changed_data:
                print(field)
            if form.is_valid():
                moment = form.save()
                moment.save()
                return HttpResponseRedirect(reverse(app.views.welcome)) # reverse 视图全称方法
        # else:
        #     raise ValidationError("请修改后提交")
    else:
        form = MomentForm()
    PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    return render(request, os.path.join(PROJECT_ROOT, 'app/templates', 'moments_input.html'), {'form': form})