Difference between revisions of "Django"
Jump to navigation
Jump to search
Line 28: | Line 28: | ||
'DIRS': [os.path.join(BASE_DIR, "myapp/templates")] | 'DIRS': [os.path.join(BASE_DIR, "myapp/templates")] | ||
* Edit the views.py in your myapp folder | |||
def myview(request): | |||
return render(request, "index.html") | |||
* create a route file called urls.py | |||
from django.urls import path | |||
from . import views | |||
urlpatterns = [ | |||
path('myview/', views.myview) | |||
] | |||
===[[Programming| Category]]=== | ===[[Programming| Category]]=== |
Revision as of 17:29, 26 April 2023
Create a new project
- First create a main dir django etc..
- cd into directory
django-admin startproject projectname
- this will create the projectname within the main directory
- cd into directory
python manage.py runserver
- To specify a different port
python manage.py runserver 8080
Create a Django App
python manage.py startapp myapp
- this will create an new app in the projectname folder
- cd into my app folder and create a folder called templates
- create an html file in the templates folder
- Link the new template folder to the project
- edit the settings.py file
import os
- Scroll down to "TEMPLATES", edit section DIRS
'DIRS': [os.path.join(BASE_DIR, "myapp/templates")]
- Edit the views.py in your myapp folder
def myview(request): return render(request, "index.html")
- create a route file called urls.py
from django.urls import path from . import views
urlpatterns = [ path('myview/', views.myview) ]