0% found this document useful (0 votes)
8 views

Project Languages Program

Uploaded by

Srihari Murali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Project Languages Program

Uploaded by

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

Develop a Model form for student that contains his topic chosen for project, languages used and

duration with a model called project

In the proj plangs->urls.py

from django.contrib import admin


from django.urls import path,include

urlpatterns = [
path('admin/', admin.site.urls),
path('',include('durt.urls')),
]

In the project settings.py

'DIRS': [BASE_DIR,'templates'],
In the templates folder->project_form.html
<!-- project_form.html -->

<!DOCTYPE html>
<html>
<head>
<title>Student Project Form</title>
</head>
<body>
<h2>Student Project Form</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
</body>
</html>

In the templates folder->success.html


<html>
<head>abcd</head>
<body>Success</body>
</html>

In tha app durt->forms.py

from django import forms


from .models import Project

class ProjectForm(forms.ModelForm):
class Meta:
model = Project
fields = ['topic', 'languages_used', 'duration']
in the app durt-> models.py

from django.db import models

class Project(models.Model):
topic = models.CharField(max_length=100)
languages_used = models.CharField(max_length=100)
duration = models.CharField(max_length=50)

in the app durt->urls.py

from django.urls import path


from . import views

urlpatterns = [
path('project_form/', views.project_form, name='project_form'),
path('success/', views.success,name='success'),
]

in the app durt->urls.py

from django.shortcuts import render, redirect


from .forms import ProjectForm

def project_form(request):
if request.method == 'POST':
form = ProjectForm(request.POST)
if form.is_valid():
form.save()
return redirect('success') # Redirect to success page after form
submission
else:
form = ProjectForm()
return render(request, 'project_form.html', {'form': form})

def success(request):
return render(request, 'success.html') # A simple success page

in the durt->admin.py

from django.contrib import admin


from durt.models import Project
# Register your models here.
admin.site.register(Project)

You might also like