Your location:Tech News>News>Script>Several ways to authenticate before finishing the form is submitted

Latest News

Several ways to authenticate before finishing the form is submitted

Author:fsadmin

Views:

锘�

? .

Django?校JavaScript?效.html?

formpage1.html

? :

Example1

?(?)


first_name:
last_name:


formpage2.html

? :

Example2

?()


first_name:
last_name:


formpage3.html

? :

Example3

?()


first_name:
last_name:


?URL

-------------------------------------------------- ------------------------------

-------------------------------------------------- ------------------------------

views.py

? :

#coding: utf-8

from django.http import HttpResponse

from django.shortcuts import render_to_response

def DealWithForm1 (request):

if request.method == "POST":

FirstName = request.POST.get ( ''firstname'', '''')

LastName = request.POST.get ( ''lastname'', '''')

if FirstName and LastName:

response = HttpResponse ()

response.write ( ""+ FirstName +" "+ LastName + u" ")

return response

else:

response = HttpResponse ()

response.write ( '''')

return response

else:

return render_to_response ( ''formpage1.html '')

def DealWithForm2 (request):

if request.method == "POST":

FirstName = request.POST.get ( ''firstname'', '''').encode ( "utf-8")

LastName = request.POST.get ( ''lastname'', '''').encode ( "utf-8")

if FirstName and LastName:

html = ""+ FirstName +" "+ LastName +" "+""

return HttpResponse (html)

else:

response = HttpResponse ()

response.write ( '''')

return response

else:

return render_to_response ( ''formpage2.html '')

def DealWithForm3 (request):

if request.method == "POST":

FirstName = request.POST.get ( ''firstname'', '''')

LastName = request.POST.get ( ''lastname'', '''')

if FirstName and LastName:

response = HttpResponse ()

response.write ( ''''+ FirstName + LastName + u'' '')

return response

else:

response = HttpResponse ()

response.write ( '''')

return response

else:

return render_to_response ( ''formpage3.html '')

urls.py

? :

from django.conf.urls.defaults import patterns, include, url

import views

from django.conf import settings

urlpatterns = patterns ( '''',

url (r ''^ Resource / (?P.*) $ '','' Django.views.static.serve '', {'' document_root '': settings.STATIC_RESOURCE}),

url (r ''^ DealWithForm1'', ''views.DealWithForm1 ''),

url (r ''^ DealWithForm2'', ''views.DealWithForm2 ''),

url (r ''^ DealWithForm3'', ''views.DealWithForm3 ''),

)

settings.py

? :

# Django settings for CheckFormBeforeSubmit project.

import os

HERE = os.path.abspath (os.path.dirname (__ file__))

DEBUG = True

TEMPLATE_DEBUG = DEBUG

.

STATIC_RESOURCE = os.path.join (HERE, "resource")

.

MIDDLEWARE_CLASSES = (

''Django.middleware.common.CommonMiddleware '',

''Django.contrib.sessions.middleware.SessionMiddleware '',

''Django.middleware.csrf.CsrfViewMiddleware '',

''Django.contrib.auth.middleware.AuthenticationMiddleware '',

''Django.contrib.messages.middleware.MessageMiddleware '',

''Django.middleware.csrf.CsrfResponseMiddleware '',

)

ROOT_URLCONF = ''CheckFormBeforeSubmit.urls''

TEMPLATE_DIRS = (

os.path.join (HERE, ''template''),

# Put strings here, like "/ home / html / django_templates" or "C: / www / django / templates".

# Always use forward slashes, even on Windows.

# Do not forget to use absolute paths, not relative paths.

)

.

: Js校?js?js (?)?写?js?JSJS()

Recommend article

Relate article