Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
view option in Django
#1
Hi all
I am creating a django project . I have 3 html pages
Index.html - it contains form
result.html - it will display a report when i click on submit in index.html
table.html - It contains a database data from index.html . I have delete & view option in my table when click on view i want to display result.html page for different entries.
what type of code should i use can anyone please explain.
Reply
#2
(Mar-22-2024, 10:54 AM)Sowmya Wrote: Hi all
I am creating a django project . I have 3 html pages
Index.html - it contains form
result.html - it will display a report when i click on submit in index.html
table.html - It contains a database data from index.html . I have delete & view option in my table when click on view i want to display result.html page for different entries.
what type of code should i use can anyone please explain.
To achieve the described functionality in your Django project, you would need to implement the following:

1-URL Configuration: Define URL patterns in your Django project's urls.py file to map the URLs to corresponding views.

2-Views: Create view functions in your Django application's views.py file to handle the logic for rendering each HTML page and processing form submissions.

3-Templates: Develop HTML templates for each page (index.html, result.html, and table.html) in the appropriate directory within your Django application's templates folder.

4-Forms: Define a Django form class in your application's forms.py file to handle form validation and processing.

Here's a brief overview of how you can structure your code:

urls.py:

python
Copy code
from django.urls import path
from . import views

urlpatterns = [
path('', views.index, name='index'),
path('result/', views.result, name='result'),
path('table/', views.table, name='table'),
# Add other URL patterns as needed
]
views.py:

python
Copy code
from django.shortcuts import render, redirect
from .forms import YourFormClass

def index(request):
if request.method == 'POST':
form = YourFormClass(request.POST)
if form.is_valid():
# Process form data
# Redirect to result page
return redirect('result')
else:
form = YourFormClass()
return render(request, 'index.html', {'form': form})

def result(request):
# Logic to generate report data
return render(request, 'result.html', {'report_data': report_data})

def table(request):
# Logic to retrieve and display data from the database
return render(request, 'table.html', {'database_data': database_data})
forms.py:

python
Copy code
from django import forms

class YourFormClass(forms.Form):
# Define form fields here
In your table.html, you would need to include buttons or links to view and delete entries, and when clicking on "view," you can navigate to the result.html page with the corresponding data.

Ensure to replace placeholders like YourFormClass, report_data, and database_data with your actual form class, report data, and database data respectively. Also, customize the views and templates according to your specific requirements.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python django view error ZeeKolachi 1 375 Mar-18-2024, 03:14 PM
Last Post: Sowmya
  Django: View is unable to find attributes of database model pythonpaul32 0 535 Dec-07-2023, 06:38 PM
Last Post: pythonpaul32
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,335 Jun-30-2019, 12:21 AM
Last Post: scidam
  Django - Passing data from view for use client side with JavaScript in a template bountyhuntr 0 3,645 Jun-11-2018, 06:04 AM
Last Post: bountyhuntr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020