zoukankan      html  css  js  c++  java
  • django 自定义表单

    创建一个1.html的东西

    <html>
    <body>
        <form method='post'>
            {{form.as_p}}
            <input type="submit" name="ok" />
        </form>
    </body>
    </html>
    
    

    创建并写一个form.py

    from django import forms
    
    class Mybook(forms.Form):
        name=forms.CharField()
        author=forms.CharField()
        date=forms.CharField()
    
    

    修改views

    from django.shortcuts import render
    from django.shortcuts import render_to_response
    from django.forms     import *
    from django.http      import HttpResponse
    from myapp.models     import *
    
    def hello(request):
        if request.method == 'post':
            form=Mybook(request.POST)
            if form.is_valid():
                data=form.cleaned_data
                title=data['title']
            return HttpResponse(title)
    
        form=Mybook()
        return render_to_response('1.html',{'form':form})
    

    修改urls.py

    from django.conf.urls import patterns, include, url
    from django.contrib import admin
    
    from myapp.views import *
    
    urlpatterns = patterns('',
        # Examples:
        # url(r'^$', 'myproj.views.home', name='home'),
        # url(r'^blog/', include('blog.urls')),
    
        url(r'^admin/', include(admin.site.urls)),
        (r'^hello/$',hello)
    )
    
    
  • 相关阅读:
    ImageView一例
    TextView之一:子类的常用属性
    TextView之二:常用属性
    Android中的消息机制:Handler消息传递机制
    关于LayoutParams
    LinearLayout的一些注意事项
    支付宝扫描二维码登录网站
    Cok
    Cok
    STM32的USART
  • 原文地址:https://www.cnblogs.com/yufenghou/p/5470823.html
Copyright © 2011-2022 走看看