Skip to content

Instantly share code, notes, and snippets.

@spidezad
Last active January 16, 2020 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spidezad/bc7a36457705e9d8ef6567c6299daab4 to your computer and use it in GitHub Desktop.
Save spidezad/bc7a36457705e9d8ef6567c6299daab4 to your computer and use it in GitHub Desktop.
djangoBasic
## From Django Tutorial
# Create Project
django-admin startproject mysite
# Create Apps
python manage.py startapp polls
# Add app to settings.py
# Create polls/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
# Create polls/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
# Update in mysite/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
# Migration
python manage.py makemigrations
python manage.py migrate
python manage.py makemigrations polls
python manage.py migrate polls
# Run Server
python manage.py runserver
# to listen on all available public IPs
python manage.py runserver 0:8000
# Make the poll app modifiable in the admin
# polls/admin.py
admin.site.register(app_model)
NB:Django will choose the first template it finds whose name matches, and if you had a template with the same name in a different application, Django would be unable to distinguish between them
==> templates/app/some.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment