route request
When routes a request, it is doing a url mapping. It uses path function. This function accepts three parameters. The first is url, the second is the function to call in the view module. The third one is the name for this path. It will be used when we want to add a link in other pages. We use the name to refer to the page.
from django.urls import path
from . import views
app_name = 'learning_logs'
urlpatterns = [
# home page
path('', views.index, name='index'),
path('topics/', views.topics, name='topics')
]
Access django sqlite3 db
If get this error message: CommandError: You appear not to have the 'sqlite3' program installed or on your path, install sqlite3 in machine first
sudo apt-get install sqlite3
# need to do it in virtual env (source ..bin/activate)
python manage.py dbshell
# also can do this
sqlite3 filename
# list tables
.tables
# see all table schema
.schema
# show table content. use normal sql select
Start server
# 9000 is port number. If port number is not provided, will use 8000 as default port
python manage.py runserver 9000
No comments:
Post a Comment