Django is the high-level python framework that is used to create secure web applications in the other python framework.
Go to the youtube video link:
Home page view:
Step1:
Open editor: pycharm
Step2:
Create a project “ems” using
>django-admin startproject ems
Step3:
Create app “employee” after change directory to “ems”
./ems> python manage.py startapp employee
Step4:
Creating superuser for admin
>python manage.py createsuperuser
Enter admin username, password
Step5:
Apply two-step migrations
>python manage.py makemigrations
>python manage.py migrate
Step6:
Run using
>python manage.py runserver
Step7:
Create models in models.py in-app “employee”
Step8:
Creating methods in views.py in-app “employee”
Step9:
Add URL to the urls.py in project folder “ems” and including “employee”
URLs here.
Write all coding parts which is in the zip file and you can get the result as per below screenshots.
Coding Parts:
urls.py
from django.urls import path, include
from employee.views import user_login, user_logout, success, ProfileUpdate, MyProfile
from django.contrib import admin
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('poll.urls')),
path('employee/', include('employee.urls')),
path('', user_login, name='user_login'),
path('success/', success, name='user_success'),
path('logout/', user_logout, name='user_logout'),
path('profile/', MyProfile.as_view(), name='my_profile'),
path('profile/update/', ProfileUpdate.as_view(), name='update_profile'),
]
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
class Profile(models.Model):
usr = models.OneToOneField(User, on_delete=models.CASCADE)
designation = models.CharField(max_length=20, null=False, blank=False)
salary = models.IntegerField(null=True, blank=True)
class Meta():
ordering = ('-salary',)
def __str__(self):
return "{0} {1}".format(self.usr.first_name, self.usr.last_name)
@receiver(post_save, sender=User)
def user_is_created(sender, instance, created, **kwargs):
print(created)
if created:
Profile.objects.create(usr=instance)
else:
instance.profile.save()
Above URLs shows the path and page which is used in this project, if you need complete code and other related than you can contact us at here:
If you need other project assignment help or programming help related to the Django projects then you can contact us at the below address:
Kommentare