Open PyxYuYu opened 7 years ago
One always has time enough, if one will apply it well.
open.html
URL
forms.py
表单函数 forms.py
Django
forms.Form
最基本的创建方式,自定义表单的各种属性
form django import forms class UrlForm(forms.Form): url = forms.CharField() urls = forms.CharField(required=False, widget=forms.Textarea) def __unicode__(self): return self.url
widget
urls
CharField
forms.ModelForm
Model
ModelForm
同时 forms.ModelForm 也支持自定义表单的属性
from django import forms from .models import Url class UrlForm(forms.ModelForm): class Meta: model = Url fields = ('url', 'urls')
Url
TextField
视图函数 views.py
views.py
如果 HTTP 以 POST 方式提交,那么就将表单内容保存至数据库
HTTP
POST
from django.shortcuts import render from .forms import UrlForm def url_sql(request): if request.method == 'POST': form = UrlForm(request.POST) if form.is_valid(): url = form.save(commit=False) url.save() form.save() else: form = UrlForm() return render(request, 'sqliscan/open.html', {'form': form})
csrf_token
0x01 DSScan
open.html
URL
至数据库 ,所以新建forms.py
表单函数表单函数
forms.py
Django
中表单提供了两种创建表单的方式forms.Form
最基本的创建方式,自定义表单的各种属性
widget
定义urls
为多行表单(默认CharField
为单行)forms.ModelForm
Model
,那么可以用forms.ModelForm
来节省大量代码(即:数据模型中的字段恰好都需要表单来提交时,使用ModelForm
即可节省代码)同时
forms.ModelForm
也支持自定义表单的属性urls
即数据模型Url
函数中定义的TextField
,无需widget
定义多行URL
保存至数据库,用第一种方式自定义创建表单即可视图函数
views.py
如果
HTTP
以POST
方式提交,那么就将表单内容保存至数据库open.html
就需要显示这个表单open.html
csrf_token