diff --git a/docs/day1.md b/docs/day1.md index cf4f210..8b6bcd3 100644 --- a/docs/day1.md +++ b/docs/day1.md @@ -124,7 +124,7 @@ Before we can dive into our web project we have to cover some Python basics. Let ![print_gb](img/day1/print_gb.png) -1. Finally add `def middle_stuff():` above the remaining code +1. Finally add `def middle_stuff():` above the remaining cod ![middle_stuff](img/day1/middle_stuff.png) @@ -140,6 +140,118 @@ Before we can dive into our web project we have to cover some Python basics. Let print_goodbye() ``` -3. Type `python my_program.py` in the terminal and press enter. Now everything prints in order! +1. Type `python my_program.py` in the terminal and press enter. Now everything prints in order! - ![in_order](img/day1/in_order.png) \ No newline at end of file + ![in_order](img/day1/in_order.png) + +## A Django Project + +Now that we can write some basic python we can begin our django project. Let's start by creating a view. + +1. Close out of my_program.py + +1. In the terminal type `django-admin startapp mysite` + + ![startapp](img/day1/startapp.gif) + +1. Expand the `config` folder by clicking on it + + ![config](img/day1/config.png) + +1. Click on `settings.py` to open it + +1. Scroll down to line 33 and add `mysite` above `'django.contrib.admin'` + + ![add_mysite](img/day1/add_mysite.png) + +1. Save with ctrl+S + +1. Click on `urls.py` to open it + + ![urls](img/day1/urlspy.png) + +1. On line 17 add `, include` after `from django.urls import path` + + ![include](img/day1/include.png) + +1. Add `path('', include('mysite.urls')),` above `path('admin/', admin.site.urls),` + + ![mysiteurls](img/day1/mysiteurls.png) + +1. Expand the newly created `mysite` folder by clicking on it + + ![mysite](img/day1/mysite.png) + +1. Right click on `mysite` and click "New Folder". Name it `templates` + + ![templates](img/day1/templates.gif) + +1. Right click on `templates` and click "New Folder". Name it `mysite` + + ![mysitetemplate](img/day1/mysitetemplates.gif) + +1. Right click on the `mysite` folder inside `templates` and click "New File". Name it `index.html` + + ![index](img/day1/index.gif) + +1. Open `index.html` by clicking on it + +1. Add the following to index.html + + ```html + + + {{ data }} + + + ``` + + ![indexdata](img/day1/indexdata.png) + +1. Save with ctrl+S + +1. Open `views.py` by clicking on it + +1. In views.py under line 3 add the following: + + ```python + def index(request): + return render( + request, + "mysite/index.html", + {"data": "hello"} + ) + ``` + + ![defindex](img/day1/defindex.png) + +1. Save with ctrl+S + +1. Right click on `mysite` and click "New File". Name it `urls.py` + + ![createurls](img/day1/createurls.gif) + +1. Add the following to urls.py: + + ```python + from django.urls import path + from . import views + + urlpatterns = [ + path('', views.index), + ] + ``` + + ![indexpath](img/day1/indexpath.png) + +1. Save with ctrl+S + +1. In the terminal type `python manage.py runserver` + + ![runserver](img/day1/runserver.gif) + +1. In your browser navigate to + + ![hello](img/day1/hello.gif) + +You've now passed python data to a browser! We'll explore what this really means in Day 2. \ No newline at end of file diff --git a/docs/img/day1/add_mysite.png b/docs/img/day1/add_mysite.png new file mode 100644 index 0000000..b471c3d Binary files /dev/null and b/docs/img/day1/add_mysite.png differ diff --git a/docs/img/day1/config.png b/docs/img/day1/config.png new file mode 100644 index 0000000..2a80b74 Binary files /dev/null and b/docs/img/day1/config.png differ diff --git a/docs/img/day1/createurls.gif b/docs/img/day1/createurls.gif new file mode 100644 index 0000000..cbfb008 Binary files /dev/null and b/docs/img/day1/createurls.gif differ diff --git a/docs/img/day1/defindex.png b/docs/img/day1/defindex.png new file mode 100644 index 0000000..1de28af Binary files /dev/null and b/docs/img/day1/defindex.png differ diff --git a/docs/img/day1/hello.gif b/docs/img/day1/hello.gif new file mode 100644 index 0000000..642e22c Binary files /dev/null and b/docs/img/day1/hello.gif differ diff --git a/docs/img/day1/include.png b/docs/img/day1/include.png new file mode 100644 index 0000000..9b27036 Binary files /dev/null and b/docs/img/day1/include.png differ diff --git a/docs/img/day1/index.gif b/docs/img/day1/index.gif new file mode 100644 index 0000000..becb0de Binary files /dev/null and b/docs/img/day1/index.gif differ diff --git a/docs/img/day1/indexdata.png b/docs/img/day1/indexdata.png new file mode 100644 index 0000000..d673557 Binary files /dev/null and b/docs/img/day1/indexdata.png differ diff --git a/docs/img/day1/indexpath.png b/docs/img/day1/indexpath.png new file mode 100644 index 0000000..ad6c5bd Binary files /dev/null and b/docs/img/day1/indexpath.png differ diff --git a/docs/img/day1/mysite.png b/docs/img/day1/mysite.png new file mode 100644 index 0000000..83eebd9 Binary files /dev/null and b/docs/img/day1/mysite.png differ diff --git a/docs/img/day1/mysitetemplates.gif b/docs/img/day1/mysitetemplates.gif new file mode 100644 index 0000000..9c20b63 Binary files /dev/null and b/docs/img/day1/mysitetemplates.gif differ diff --git a/docs/img/day1/mysiteurls.png b/docs/img/day1/mysiteurls.png new file mode 100644 index 0000000..005439b Binary files /dev/null and b/docs/img/day1/mysiteurls.png differ diff --git a/docs/img/day1/runserver.gif b/docs/img/day1/runserver.gif new file mode 100644 index 0000000..2272972 Binary files /dev/null and b/docs/img/day1/runserver.gif differ diff --git a/docs/img/day1/startapp.gif b/docs/img/day1/startapp.gif new file mode 100644 index 0000000..cfdfeec Binary files /dev/null and b/docs/img/day1/startapp.gif differ diff --git a/docs/img/day1/templates.gif b/docs/img/day1/templates.gif new file mode 100644 index 0000000..5f296a4 Binary files /dev/null and b/docs/img/day1/templates.gif differ diff --git a/docs/img/day1/urlspy.png b/docs/img/day1/urlspy.png new file mode 100644 index 0000000..9d03d51 Binary files /dev/null and b/docs/img/day1/urlspy.png differ