コード例 #1
0
class Index(View):
    d = z()
    initial_data = {
        "integer": 10000,
        "email": "*****@*****.**",
        "multiemail": "[email protected],[email protected]",
        "name": "<google__google__google>",
        "url": "http://google.co.jp"
    }
    d["mode"] = "index"

    def get(self, request, *args, **kwargs):
        self.d["form1"] = forms.Form(self.initial_data)
        return render(request, "app/index.html", self.d)

    def post(self, request, *args, **kwargs):
        form1 = forms.Form(request.POST)
        if form1.is_valid():
            self.d["form1"] = form1
        else:
            self.d["form1"] = form1
            print(form1.non_field_errors())
            print(form1.has_error("integer"))
            print(form1.errors.as_json())
        return render(request, "app/index.html", self.d)
コード例 #2
0
class Tashizan(View):
    initials = {"char1": "適当", "check": True}
    d = z()
    d["mode"] = "index"
    form_class = forms.Form
    template_name = "app/index.html"

    def get(self, request, *args, **kwargs):
        self.d["form"] = self.form_class(self.initials)
        return render(request, self.template_name, self.d)
コード例 #3
0
class Result(View):
    d = z()
    d["mode"] = "result"

    def post(self, request, *args, **kwargs):
        form1 = forms.Form(request.POST)
        #request.POSTで受け取る場合
        if form1.is_valid():
            a1 = request.POST["number1"]
            b1 = request.POST["number2"]
            c1 = a1 + b1
            self.d["c1"] = c1

    #form.cleaned_dataで受け取る場合
        if form1.is_valid():
            a = form1.cleaned_data["number1"]
            b = form1.cleaned_data["number2"]
            c = a + b
            self.d["c"] = c
        return render(request, "app/index.html", self.d)
コード例 #4
0
class Tashizan(View):
    initial_numbers = {"number1": 1, "number2": 2}
    d = z()
    d["mode"] = "index"
    d["form1"] = forms.Form(initial_numbers)
    template_name = "app/index.html"
    form_class2 = forms.Form2

    def get(self, request, *args, **kwargs):
        self.d["form2"] = self.form_class2(self.initial_numbers)
        return render(request, self.template_name, self.d)

    def post(self, request, *args, **kwargs):
        form2 = self.form_class2(request.POST)
        if form2.is_valid():
            e = form2.cleaned_data
            a = form2.cleaned_data["number1"]
            b = form2.cleaned_data["number2"]
            c = a + b
            e["number3"] = c
            self.d["form2"] = self.form_class2(e)
        return render(request, self.template_name, self.d)
コード例 #5
0
from . import views
from django.views.generic import TemplateView
from ajax.views import z
from django.urls import path, re_path, include

d = z()
d["mode"] = "index"
d["karalist"] = []
d["karamojiretu"] = ""
d["zero"] = 0
d["zerofloat"] = 0.0

app_name = "app"
urlpatterns = [
    path("index/",
         TemplateView.as_view(template_name="app/index.html"),
         d,
         name="index"),
]
コード例 #6
0
ファイル: views.py プロジェクト: FujitaHirotaka/djangoruler3
 def get_context_data(self, **kwargs):
     d = super().get_context_data(**kwargs)
     e = z()
     d.update(e)
     d["mode"] = "detail"
     return d
コード例 #7
0
ファイル: views.py プロジェクト: FujitaHirotaka/djangoruler3
 def get_context_data(self, *args, **kwargs):
     d = super().get_context_data(*args, **kwargs)
     e = z()
     e["mode"] = "delete"
     d.update(e)
     return d