Scaling the Project
Note: This section is optional but essential for scaling the project.
For the sake of simplicity, the styling portion of this course is skipped. Please download the templates from the course resources.
Database Setup
Models
In Django, models are Python classes that represent database tables.
Creating a Model
Let's create a Profile model by extending the default User model provided by Django. It's recommended to define models within the respective app for better organization.
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
profile_pic = models.ImageField(blank=True, null=True, default='default.png')
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
While the process may seem straightforward, understanding the use of the image field and the significance of 'default.png' requires delving deeper into the configuration of media settings.
Register the Model
Register the Profile model in the admin panel for easy management.
from django.contrib import admin
from .models import Profile
admin.site.register(Profile)
Note: Django default uses SQLite Database as db.sqlite3 which can be seen in the project root.
Migration
To apply the model changes to the database, perform migrations:


If the migration process completes without errors, your database is ready for use.
Configure Media Files
-
Install Pillow library for image processing:
-
Configure media settings in
settings.py: -
Update project-level URLs to handle media files:
your_project_name/urls.pyfrom django.contrib import admin from django.urls import path, include from django.conf import settings from django.conf.urls.static import static # import static urlpatterns = [ path('admin/', admin.site.urls), path('', include('lynx.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # configure to use the media path
SUDO
Create SUDO
Create a superuser (sudo) account for admin operations:
Follow the prompts to set the username, email, and password for the superuser.

Admin Panel Access
Access the admin panel using the superuser credentials at localhost:port/admin while the server is running.
return redirect('login')
context = {'form': form}
return render(request, 'your_app_name/register.html', context=context)
def login(request):
return render(request, 'your_app_name/login.html')
```
Crispy Forms Integration
Crispy Forms is a popular third-party Django application that provides a convenient way to style and render Django forms by integrating with popular CSS frameworks like Bootstrap, Foundation, and Bulma.
-
Install the crispy forms library:
Note: Install version
1.14.0only as V2.0 onwards things have changed. -
Register crispy forms in
settings.py: -
Apply crispy forms to
registrationform in the template:register.html<div class="container bg-white shadow-md p-5 form-layout"> <h1> Register </h1> <br> <form action="" method="post" autocomplete="off"> {% csrf_token %} {{ form.username|as_crispy_field }} <br> {{ form.email|as_crispy_field }} <br> {{ form.password1|as_crispy_field }} <br> {{ form.password2|as_crispy_field }} <br> <input class="btn btn-primary" type="submit" value="Submit"> </form> </div>
After registration, users can log in using their credentials.
User Registration
After completing the form accurately, you will be redirected to the login page.
The admin panel now displays a user named 'demo'.
Note: The remaining part of the Django Tutorial will be updated soon!