If you are new for Django template, here you start with creating new apps and pages.
full-version
or starter-kit
To create a new app, open your terminal and run the following command python manage.py startapp APPNAME.
Let's create an app with name test (django suggest snake_case name for application).
apps
folder for the django application. so we suggest that you navigate to folder apps and use python ../manage.py startapp test
test
📂 migrations
│ └──📄 __init__.py
├── 📄 __init__.py
├── 📄 admin.py
├── 📄 apps.py
├── 📄 models.py
├── 📄 tests.py
└── 📄 views.py
full-version
or starter-kit
Create templates
folder with test.html
file.
test
📂 migrations
│ └──📂 __init__.py
📂 templates
│ └──📄 test.html
├── 📄 __init__.py
├── 📄 admin.py
├── 📄 apps.py
├── 📄 models.py
├── 📄 tests.py
├── 📄 urls.py
└── 📄 views.py
Use the following code in test.html
file.
{% extends layout_path %}
{% load static %}
{% load i18n %}
{% block title %} Test Page - Starter Kit{% endblock title %}
{% block content %}
<h4 class="py-3 mb-6">{% translate "Title: Test Page" %}</h4>
<p>Content: Test page.</p>
{% endblock %}
For views.py
content we have provided a snippet, Which can be accessed by django-view.
from django.views.generic import TemplateView
from web_project import TemplateLayout
"""
This file is a view controller for multiple pages as a module.
Here you can override the page view layout.
Refer to test/urls.py file for more pages.
"""
class testView(TemplateView):
# Predefined function
def get_context_data(self, **kwargs):
# A function to init the global layout. It is defined in web_project/__init__.py file
context = TemplateLayout.init(self, super().get_context_data(**kwargs))
return context
Create urls.py
(Startapp don't create urls.py
file).
from django.urls import path
from .views import testView
urlpatterns = [
path(
"",
testView.as_view(template_name="test.html"),
name="test",
),
]
Add the app (We can get this name form test/apps.py) in config/settings.py
and config/urls.py
which is in config folder.
INSTALLED_APPS = [
"apps.test"
]
urlpatterns = [
path("test/", include("apps.test.urls")),
]
apps.py
file. In the name
parameter add apps as prefix. Ex: apps.test
from django.apps import AppConfig
class TestConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.test'
Add page link to vertical & horizontal menu. Find vertical_menu.json
and horizontal_menu.json
files inside templates/layout/partials/menu
folder.
Option 1: To add menu item as main menu:
{
"url": "test",(in this template this url take name-url)
"name": "Test Page",
"icon": "menu-icon tf-icons bx bx-envelope",
"slug": "test"
},
Option 2: To add menu item as sub menu:
{
"name": "Test",
"icon": "menu-icon tf-icons bx bx-file",
"slug": "Test",
"submenu": [
{
"url": "test",
"name": "Test Page",
"slug": "test"
},
]
},
search-vertical.json
and search-horizontal.json
inside src/assets/json/
folder.{
"name": "Test Page",
"icon": "bx-home-alt",
"url": "/pages/testPage/"
},
locale/fr/django.po
{all language po} file to display in multi language.msgid "Test"
msgstr "Tablu"
python manage.py compilemessages
To serve your project to localhost, you need to run the command python manage.py runserver