step 1:- write code in models.py file in your app folder :-
step 2:- write code in forms.py file in your app folder :-
step 3:- write code in views.py file in your app folder :-
step 4:- templates file code index.html file :-
to copy above code :-
step 1 Models.py :-
# [Trainer
class Trainer|(models. Model):
full_name=models.CharField(max_Length=100)
username=models.CharField(max_Length=100,null=True)
pwd=models.CharField(max_Length=5@,null=True)
mobile=models.CharField(max_Length=100)
address=models.TextField()
is_active=models.BooleanField(default=False)
detail=models.TextField()
img=models.ImageField(upload_to="trainers/")
def __str__(self):
return str(self.full_name)
def image_tag(self):
if self.img:
return mark_safe('<img src="%s" width="80" />' % (self.img.url))
[EH
return 'no-image’
Step 2 : forms.py
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User
from . import models
class EnquiryForm(forms.ModelForm):
class Meta:
model=models.Enquiry
fields=('full_name', ‘email’, 'detail’)
class SignUp(UserCreationForm):
class Meta:
model=User
fields=('first_name', 'last_name','email’, ‘username’, 'passwordl’, 'password2')
class ProfileForm(UserChangeForm):
class Meta:
model=User|
fields=('first_name', 'last_name', ‘email’, username’)
class TrainerLoginForm(models.ModelForm):
class Meta:
model-Trainer|
fields=('username’, 'pwd")
step 3:-(views.py file )
def trainerlogin(request):
msg=""
if request.method=='POST":
username=request.POST[ ‘username’ ]
pwd=request.POST[ "pwd" ]
trainer=models.Trainer.objects. filter (username=username,pwd=pwd).count()
if trainer > 0:
request.session[ 'trainerLogin’]=True
return redirect('/trainer_dashboard")
else:
msg="Invalid!!"
form=forms.TrainerLoginForm
return render(request, 'trainer/login.html’,{'form’:form, 'msg':msg})
def trainerlogout(request):
del request.session['trainerLogin’]
return redirect('/trainerlogin')
step 4:-
</a>
<ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
{% if not request.user.is_authenticated %}
{% if request.session.trainerLogin %}
<li><a class="dropdown-item" href="{% url “trainerlogout" %}">Trainer
Logout</a></1i>
{% else %}
<li><a class="dropdown-item" href="{% url 'trainerlogin’' %}">Trainer Login
</a></1li>
<li><a class="dropdown-item" href="{% url ‘signup’ %}">Register</a></li>
<li><a class="dropdown-item" href="{% url ‘login’ %}">Login</a></1li>
{% endif %}
{% else %}
<li><a class="dropdown-item" href="{% url 'user_dashboard' %}">Dashboard</a>
</1i>
<li><a class="dropdown-item" href="{% url 'update_profile' %}">Profile</a></
1i>
<li><a class="dropdown-item" href: ">Settings</a></1i>
<li><a class="dropdown-item" href="{% url 'logout' %}">Logout</a></1i>
{% endif %}
</ul>
</1i>
Sign up here with your email
ConversionConversion EmoticonEmoticon