conda create --name VenvName PackageName=version(3.5)
source activate MyDjangoEnv
source deactivate
django-admin startproject first_project
- init.py - This is a blank Python script that due to its special name let’s Python know that this directory can be treated as a package
- settings.py - This is where you will store all your project settings
- urls.py - This is a Python script that will store all the URL patterns for your project. Basically the different pages of your web application.
- wsgi.py - This is a Python script that acts as the Web Server Gateway Interface. It will later on help us deploy our web app to production
- manage.py - This is a Python script that we will use a lot. It will be associates with many commands as we build our web app!
conda install django
python manage.py runserver
Note - settings.py change DEBUG to false to avoid log message to user
python manage.py startapp first_app
- init.py - This is a blank Python script that due to its special name let’s Python know that this directory can be treated as a package
- admin.py - You can register your models here which Django will then use them with Django’s admin interface.
- apps.py - Here you can place application specific configurations
- models.py - Here you store the application’s data models
- tests.py - Here you can store test functions to test your code
- views.py - This is where you have functions that handle requests and return responses
- Migrations folder- This directory stores database specific information as it relates to the models
Note - Inform project about the newly created app by adding app details to settings.py INSATALLED_APPS
include() function from django.conf.urls (Specific URL for app)
from django.urls import path, include
from first_app import views
urlpatterns = [
path('app/', include('first_app.urls')),
]
- Create a Template folder inside project
- Assign URL in settings.py
- Use template with expression in views.py
- Create a static folder inside project
- Assign URL in settings.py
STATIC_DIR = os.path.join(BASE_DIR,"static") STATICFILES_DIRS = [ STATIC_DIR, ]
- Load static files in html
{% load staticfiles %} <link rel="stylesheet" href="{% static "css/mystyle.css" %}"/> <img src="{% static "images/img.jpg" %}" alt=" Picture "/>