0% found this document useful (0 votes)
9 views4 pages

formViews

The document contains a Django web application that allows users to input event details through a form. It includes the views, models, forms, and templates necessary for handling event data, such as name, email, address, and event name. The application is structured with URL routing for both the project and the application, enabling the rendering of the form and saving of event data to the database.

Uploaded by

Pavan Malladi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

formViews

The document contains a Django web application that allows users to input event details through a form. It includes the views, models, forms, and templates necessary for handling event data, such as name, email, address, and event name. The application is structured with URL routing for both the project and the application, enabling the rendering of the form and saving of event data to the database.

Uploaded by

Pavan Malladi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Views.

py :

from django.shortcuts import render

from django.http import HttpResponse

from shaik.models import Event

from shaik.forms import EventForm

# Create your views here.

def studentinputview(request):

if request.method=='POST':

form=EventForm(request.POST)

if form.is_valid():

nm=form.cleaned_data['name']

ml=form.cleaned_data['mailid']

ad=form.cleaned_data['address']

pn=form.cleaned_data['phonenumber']

ag=form.cleaned_data['age']

aa=form.cleaned_data['aadharnumber']

ev=form.cleaned_data['eventname']

co=form.cleaned_data['collegename']

ro=form.cleaned_data['rollnumber']

s=Event(name=nm,mailid=ml,address=ad,phonenumber=pn,age=ag,aadharnumber=aa,eventname=
ev,collegename=co,rollnumber=ro)

s.save()

else:

form=EventForm()

return render(request,'form.html',{'form':form})

models.py :

from django.db import models


# Create your models here.

class Event(models.Model):

name=models.CharField(max_length=20)

mailid=models.CharField(max_length=30)

address=models.CharField(max_length=20)

phonenumber=models.IntegerField()

age=models.IntegerField()

aadharnumber=models.IntegerField()

eventname=models.CharField(max_length=30)

collegename=models.CharField(max_length=30)

rollnumber=models.IntegerField()

forms.py :

from django import forms

class EventForm(forms.Form):

name=forms.CharField(error_messages={'required':'Enter the name'})

mailid=forms.EmailField(error_messages={'required':'Enter the mailId'})

address=forms.CharField(error_messages={'required':'Enter the address'})

phonenumber=forms.IntegerField(error_messages={'required':'Enter the phonenumber'})

age=forms.IntegerField(error_messages={'required':'Enter the age'})

aadharnumber=forms.IntegerField(error_messages={'required':'Enter the aadhar number'})

eventname=forms.CharField(error_messages={'required':'Enter the event name'})

collegename=forms.CharField(error_messages={'required':'Enter the college name'})

rollnumber=forms.CharField(error_messages={'required':'Enter the roll number'})

admin.py:

from django.db import models

# Create your models here.


class Event(models.Model):

name=models.CharField(max_length=20)

mailid=models.CharField(max_length=30)

address=models.CharField(max_length=20)

phonenumber=models.IntegerField()

age=models.IntegerField()

aadharnumber=models.IntegerField()

eventname=models.CharField(max_length=30)

collegename=models.CharField(max_length=30)

rollnumber=models.IntegerField()

form.html :

{% load static %}

<html>

<head>

</head>

<body bgcolor="azure">

<center>

<img src="{% static 'images/istock.jpg' %}" width="600" height="600">

<h1 style="color: rgb(241, 137, 9);">WELCOME TO THE EVENT</h1>

<h2 style="color: aquamarine;">all the fields are mandatory to fill</h2>

<h2 style="color: chartreuse;">The Event list is given below</h2>

<pre><h3 style="color: darksalmon;"><br>1.Coding and Debugging 2.Spot Photography


3.FlashMob 4.Poster Presentation</h3></pre>

<form method="POST" novalidate>

{% csrf_token %}

<table border="4" style="background-color: whitesmoke;">

{{form.as_table}}

</table>
<input type="submit" value="submit"></table>

</form>

</center>

</body>

</html>

Urls.py (project) :

from django.contrib import admin

from django.urls import path,include

urlpatterns = [

path('',include('shaik.urls')),

path('admin/', admin.site.urls)

Urls.py (application):

from django.urls import path

from . import views

from django.contrib import admin

urlpatterns=[

path('',views.studentinputview,name='studentinputview')

You might also like