FILE views.py:
`from django.shortcuts import render
from django.http import HttpResponseRedirect
from .models import Club
from .forms import ClubForm
def all_clubs(request):
club_list = Club.objects.all()
return render(request,'club_list.html',{'club_list':club_list})
def add_club(request):
submitted = False
if request.method == "POST":
form = ClubForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('add_club?submitted=True')
else:
form = ClubForm
if 'submitted' in request.GET:
submitted = True
return render(request,'add_club.html',{'form':form},{'submitted':submitted}) `
FILE urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.all_clubs, name='list_clubs'),
path('add_club.html', views.add_club, name='add_clubs'),
]
FILE models.py
![ ![تصویر][1]1from django.db import models
class Club(models.Model):
club_name = models.CharField(max_length=255)
max_capacity = models.IntegerField
Mens_only = models.BooleanField(default=False)
Womens_only = models.BooleanField(default=False)
Mens_and_Womens = models.BooleanField(default=False)
manager_name = models.CharField(max_length=255)
address = models.CharField(max_length=25, blank=True)
def __str__(self):
return self.club_name
FILE forms.py
from django import forms
from django.forms import ModelForm
from .models import Club
FILE admin.py:
from django.contrib import admin
from .models import Club
admin.site.register(Club)
FILE urls.py
from django.contrib import admin
from django.urls import path
from django.urls import include
RESULT:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags must come first in the head; any other head content must come after these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Club Project</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/">All Clubs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/add_club.html">Add A Club</a>
</li>
</ul>
</div>
</div>
</nav>
<div class = "container">
</div>
<!--<h1> Here is the text in header </h1>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
</body>
</html>
متاسفانه کد اچ تی ام ال را رندر نمیکنه... مشکل از کجاست؟
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟