Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
360bd07a44 |
116
docs/day1.md
@@ -124,7 +124,7 @@ Before we can dive into our web project we have to cover some Python basics. Let
|
||||
|
||||

|
||||
|
||||
1. Finally add `def middle_stuff():` above the remaining code
|
||||
1. Finally add `def middle_stuff():` above the remaining cod
|
||||
|
||||

|
||||
|
||||
@@ -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!
|
||||
|
||||

|
||||
|
||||
## 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`
|
||||
|
||||

|
||||
|
||||
1. Expand the `config` folder by clicking on it
|
||||
|
||||

|
||||
|
||||
1. Click on `settings.py` to open it
|
||||
|
||||
1. Scroll down to line 33 and add `mysite` above `'django.contrib.admin'`
|
||||
|
||||

|
||||
|
||||
1. Save with <kbd>ctrl</kbd>+<kbd>S</kbd>
|
||||
|
||||
1. Click on `urls.py` to open it
|
||||
|
||||

|
||||
|
||||
1. On line 17 add `, include` after `from django.urls import path`
|
||||
|
||||

|
||||
|
||||
1. Add `path('', include('mysite.urls')),` above `path('admin/', admin.site.urls),`
|
||||
|
||||

|
||||
|
||||
1. Expand the newly created `mysite` folder by clicking on it
|
||||
|
||||

|
||||
|
||||
1. Right click on `mysite` and click "New Folder". Name it `templates`
|
||||
|
||||

|
||||
|
||||
1. Right click on `templates` and click "New Folder". Name it `mysite`
|
||||
|
||||

|
||||
|
||||
1. Right click on the `mysite` folder inside `templates` and click "New File". Name it `index.html`
|
||||
|
||||

|
||||
|
||||
1. Open `index.html` by clicking on it
|
||||
|
||||
1. Add the following to index.html
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<body>
|
||||
{{ data }}
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||

|
||||
|
||||
1. Save with <kbd>ctrl</kbd>+<kbd>S</kbd>
|
||||
|
||||
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"}
|
||||
)
|
||||
```
|
||||
|
||||

|
||||
|
||||
1. Save with <kbd>ctrl</kbd>+<kbd>S</kbd>
|
||||
|
||||
1. Right click on `mysite` and click "New File". Name it `urls.py`
|
||||
|
||||

|
||||
|
||||
1. Add the following to urls.py:
|
||||
|
||||
```python
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index),
|
||||
]
|
||||
```
|
||||
|
||||

|
||||
|
||||
1. Save with <kbd>ctrl</kbd>+<kbd>S</kbd>
|
||||
|
||||
1. In the terminal type `python manage.py runserver`
|
||||
|
||||

|
||||
|
||||
1. In your browser navigate to <http://localhost:8000>
|
||||
|
||||

|
||||
|
||||
You've now passed python data to a browser! We'll explore what this really means in Day 2.
|
||||
BIN
docs/img/day1/add_mysite.png
Normal file
|
After Width: | Height: | Size: 227 KiB |
BIN
docs/img/day1/config.png
Normal file
|
After Width: | Height: | Size: 168 KiB |
BIN
docs/img/day1/createurls.gif
Normal file
|
After Width: | Height: | Size: 425 KiB |
BIN
docs/img/day1/defindex.png
Normal file
|
After Width: | Height: | Size: 252 KiB |
BIN
docs/img/day1/hello.gif
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
docs/img/day1/include.png
Normal file
|
After Width: | Height: | Size: 218 KiB |
BIN
docs/img/day1/index.gif
Normal file
|
After Width: | Height: | Size: 626 KiB |
BIN
docs/img/day1/indexdata.png
Normal file
|
After Width: | Height: | Size: 240 KiB |
BIN
docs/img/day1/indexpath.png
Normal file
|
After Width: | Height: | Size: 188 KiB |
BIN
docs/img/day1/mysite.png
Normal file
|
After Width: | Height: | Size: 168 KiB |
BIN
docs/img/day1/mysitetemplates.gif
Normal file
|
After Width: | Height: | Size: 528 KiB |
BIN
docs/img/day1/mysiteurls.png
Normal file
|
After Width: | Height: | Size: 223 KiB |
BIN
docs/img/day1/runserver.gif
Normal file
|
After Width: | Height: | Size: 253 KiB |
BIN
docs/img/day1/startapp.gif
Normal file
|
After Width: | Height: | Size: 130 KiB |
BIN
docs/img/day1/templates.gif
Normal file
|
After Width: | Height: | Size: 595 KiB |
BIN
docs/img/day1/urlspy.png
Normal file
|
After Width: | Height: | Size: 234 KiB |