Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSScan(四) #75

Open
PyxYuYu opened this issue Jan 11, 2017 · 0 comments
Open

DSScan(四) #75

PyxYuYu opened this issue Jan 11, 2017 · 0 comments
Labels

Comments

@PyxYuYu
Copy link
Owner

PyxYuYu commented Jan 11, 2017

One always has time enough, if one will apply it well.

0x01 DSScan

  • 模板文件 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 ,那么可以用 forms.ModelForm 来节省大量代码(即:数据模型中的字段恰好都需要表单来提交时,使用 ModelForm 即可节省代码)
        • 同时 forms.ModelForm 也支持自定义表单的属性
           from django import forms
           from .models import Url
           
           class UrlForm(forms.ModelForm):
               class Meta:
          	     model = Url
                       fields = ('url', 'urls')
        • 此处的 urls 即数据模型 Url 函数中定义的 TextField,无需 widget 定义多行
    • 这里表单就需要将提交的 URL 保存至数据库,用第一种方式自定义创建表单即可
  • 视图函数 views.py
    • 表单函数定义完成后,逻辑部分就需要视图函数处理
      • 如果 HTTPPOST 方式提交,那么就将表单内容保存至数据库
         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})
      • 逻辑部分处理完成,模板文件 open.html 就需要显示这个表单
  • 模板文件 open.html
    • 表单在模板文件中显示需要 csrf_token
@PyxYuYu PyxYuYu added the DSScan label Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant