In this repository, you will have a template to the absolute basic app that you can create with Django and Python.
The details of this package are on my blog:
Get Started With Django (Python Tutorial)
@author: Jean-Christophe Chouinard
@title: Sr. SEO Specialist at SEEK
Blog: jcchouinard.com
Linkedin:/in/jeanchristophechouinard
Twitter:@ChouinardJC
$ git clone https://github.com/jcchouinard/Django-tutorial.git
$ pip install -r requirements.txt
or
$ conda install --file requirements.txt
$ django-admin startproject <PROJECT_NAME>
$ django-admin startproject first_django_app
$ cd <PROJECT_NAME>
$ cd first_django_app
$ python manage.py startapp <APP_NAME>
$ python manage.py startapp django_app
In your app settings.py file. first_django_app > dirst_django_app > settings.py
Go to the INSTALLED_APPS, and add your <APP_NAME> app to the list.
INSTALLED_APPS = [
'django_app',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
In the urls.py
file:
first_django_app > first_django_app > urls.py
Import the include
module.
from django.urls import include, path
Add the path('', include('<APP_NAME>.urls'))
to the list of url patterns.
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('django_app.urls'))
]
Save the file.
$ cd <APP_NAME>
$ cd django_app
$ touch urls.py
Open the urls.py file first_django_app > django_app > urls.py
$ code urls.py
Add this to the urls.py file.
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]
Save the file.
Open the views.py file first_django_app > django_app > views.py
We need to create the index route inside the views.py file.
The route will use the render module to render the index.html
page template.
def index(request):
return render(request, "<APP_NAME>/index.html")
Here is the code to have in the views.py file.
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'django_app/index.html')
$ mkdir -p templates/<APP_NAME>
$ mkdir -p templates/django_app
Inside the directory create the index.html
file.
first_django_app > django_app > templates > django_app > index.html
$ touch templates/django_app/index.html
Open the index.html
file.
first_django_app > django_app > templates > django_app > index.html
$ code templates/django_app/index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My First Django App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>My First Django App</h1>
<p>Congratulations.</p>
<p>You have built your first Django application with Python.</p>
</body>
</html>
$ cd ..
$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py runserver
Open the given URL in your browser.
http://127.0.0.1:8000/
$ conda deactivate
Python for SEO: Complete Guide (in 5 Chapters)
Learn Git and Github (Complete Guide)
Automation
WebScraping
APIs
- Google Search Console API: Complete Guide (in 4 Chapters)
- Intro to GSC API with Python (Video)
- Google Analytics Reporting API v4 using Python [2020 update]
- How to use Reddit API With Python
Others