# First Django App Following [here at djanoproject.com](https://docs.djangoproject.com/en/4.1/intro/tutorial01/) ## Install In anaconda ```bash conda install -c anaconda django ``` test: run this in an interactive shell and see if you get an error or not ```python import django ``` ## First app ```bash django-admin startproject mysite ``` structure: ``` mysite/ manage.py mysite/ __init__.py settings.py urls.py asgi.py wsgi.py ``` ```bash python manage.py runserver ``` By default this uses port `8000`, but we can ```bash python manage.py runserver 8080 python manage.py runserver 0.0.0.0:8080 ``` ## Creating the app ```bash python manage.py startapp polls ``` then in `polls/views.py` ```python from django.http import HttpResponse def index(request): return HttpResponse("Hello World") ``` and in `pools/urls.py` ```python from django.urls import path from . import views urlpatterns - [ path('', views.index, name="index") ] ``` then in `mysite/urls.py` (this is the master `urls.py` for the whole project, whereas `polls` is an app that lives within the project. ``` from django.contrib import admin from django.urls import include, path urlpatterns = [ path('polls/', include('polls.urls')) path('admin/', admin.site.urls), ] ``` you should *always* use `include()` to include other {URL} patterns, the exception being `admin.site.urls` ### path() ```python path(route, view, kwargs, name) # route -- url pattern # view -- function to delegate to # additional kwargs -- for the view function # name -- give the route a name ```