From c2fb369c00abd1d64d6f2f8d07499d267b8c77f0 Mon Sep 17 00:00:00 2001 From: rjgeng Date: Mon, 17 Jul 2023 14:32:18 -0700 Subject: [PATCH] Django-4: Section 8: Introduction to Django Framework - update --- .DS_Store | Bin 6148 -> 6148 bytes .../47_First-Django-Application-App.md | 85 ++++++++++++------ ..._Introduction-to-URLs-Views-and-Routing.md | 27 ++++++ .../49_Project-Application-Exercise.md | 30 +++++++ ...0_Project-Application-Exercise-Solution.md | 42 +++++++++ .../51_Django-Views-and-URLs-Overview.md | 29 ++++++ .../Readme.md | 49 +++++++++- README.md | 2 +- .../my_site/my_app/urls.py | 2 +- .../my_site/my_site/settings.py | 2 +- .../my_site/my_site/urls.py | 2 +- 11 files changed, 235 insertions(+), 35 deletions(-) create mode 100644 Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/48_Introduction-to-URLs-Views-and-Routing.md create mode 100644 Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/49_Project-Application-Exercise.md create mode 100644 Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/50_Project-Application-Exercise-Solution.md create mode 100644 Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/51_Django-Views-and-URLs-Overview.md diff --git a/.DS_Store b/.DS_Store index a0cdeedffdc2276abf07c37f941c68acd954a496..26c6c6350e0f7f4446b37a6da74a16506eaf10b8 100644 GIT binary patch delta 12 TcmZoMXfc?uf{|h4%4l%_9nJ)9 delta 12 TcmZoMXfc?uf{}6K%4l%_9n%DF diff --git a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/47_First-Django-Application-App.md b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/47_First-Django-Application-App.md index 029d873..43d4cc2 100644 --- a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/47_First-Django-Application-App.md +++ b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/47_First-Django-Application-App.md @@ -5,7 +5,7 @@

- + @@ -56,42 +56,46 @@ def index(request): return HttpResponse("HELLO THIS IS A VIEW INSIDE MY_APP") ``` -- mapping the view to the url in the `my_site/urls.py` +- add the `urls.py` file under `my_app`: `my_app/url.py` + +```python +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), # /my_app --> PROJECT my_app/urls.py +] +``` + +- mapping the view to the url in the PROJECT `urls.py` -- `my_site/urls.py` ```python +"""my_site URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" from django.contrib import admin from django.urls import path, include from my_app import views urlpatterns = [ - path('', views.index, name="index"), - path('my_app/', include('my_app.urls')), # new + # path('', views.index, name="index"), + path('my_app/', include('my_app.urls')), # /my_app --> my_app/urls.py path('admin/', admin.site.urls), ] ``` -- add the `my_app` to the `my_site/settings.py` - - ```python - - ... - - # Application definition - - INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'my_app' - ] - - ... - - ``` - @@ -146,6 +150,33 @@ python3 manage.py runserver

+## Exploring urls path + +- `my_site/urls.py` + +```python +from django.contrib import admin +from django.urls import path, include +from my_app import views + +urlpatterns = [ + # path('', views.index, name="index"), # NOTE: comment out this line + path('my_app/', include('my_app.urls')), + path('admin/', admin.site.urls), +] +``` + +``` +python3 manage.py runserver +``` + +

+ + + + +

+
@@ -165,4 +196,4 @@ python3 manage.py runserver --- -[Previous](./46_First-Django-Project.md) | [Next]() \ No newline at end of file +[Previous](./46_First-Django-Project.md) | [Next](./48_Introduction-to-URLs-Views-and-Routing.md) \ No newline at end of file diff --git a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/48_Introduction-to-URLs-Views-and-Routing.md b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/48_Introduction-to-URLs-Views-and-Routing.md new file mode 100644 index 0000000..111504b --- /dev/null +++ b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/48_Introduction-to-URLs-Views-and-Routing.md @@ -0,0 +1,27 @@ +# 48. Introduction to URLs, Views, and Routing + +
+ Slides: 48. Introduction to URLs, Views, and Routing + +

+ + + + + + +

+ +
+ + + +# Resources for this lecture + + +- [Slides: 07-Django-Views,Routing,URLs.pdf](https://python-ds.s3.us-west-1.amazonaws.com/Django-4-and-Python-Full-Stack-Developer-Masterclass/resources/07-Django-Views%2CRouting%2CURLs.pdf) + + +--- + +[Previous](./47_First-Django-Application-App.md) | [Next](./49_Project-Application-Exercise.md) \ No newline at end of file diff --git a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/49_Project-Application-Exercise.md b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/49_Project-Application-Exercise.md new file mode 100644 index 0000000..6481321 --- /dev/null +++ b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/49_Project-Application-Exercise.md @@ -0,0 +1,30 @@ +# 49. Project Application Exercise + +
+ Slides: 49. Project Application Exercise + +

+ + + +

+ +
+ +
+ Codebase: + +- [my_site](../../codebase/django-4/08-Introduction-to-Django/my_site/) + + +
+ +# Resources for this lecture + + +- [Slides: 07-Django-Views,Routing,URLs.pdf](https://python-ds.s3.us-west-1.amazonaws.com/Django-4-and-Python-Full-Stack-Developer-Masterclass/resources/07-Django-Views%2CRouting%2CURLs.pdf) + + +--- + +[Previous](./48_Introduction-to-URLs-Views-and-Routing.md) | [Next](./50_Project-Application-Exercise-Solution.md) \ No newline at end of file diff --git a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/50_Project-Application-Exercise-Solution.md b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/50_Project-Application-Exercise-Solution.md new file mode 100644 index 0000000..2a592cd --- /dev/null +++ b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/50_Project-Application-Exercise-Solution.md @@ -0,0 +1,42 @@ +# 50. Project Application Exercise - Solution + +
+ 50. Project Application Exercise - Solution + +- create a project + +```bash +django-admin startproject my_site +``` + +- cd into the project + +```bash +cd my_site +``` + +- create a django application + +```bash +python manage.py startapp first_app +``` + +
+ +
+ Codebase: + +- [my_site](../../codebase/django-4/08-Introduction-to-Django/my_site/) + + +
+ +# Resources for this lecture + + +- [Slides: 07-Django-Views,Routing,URLs.pdf](https://python-ds.s3.us-west-1.amazonaws.com/Django-4-and-Python-Full-Stack-Developer-Masterclass/resources/07-Django-Views%2CRouting%2CURLs.pdf) + + +--- + +[Previous](./49_Project-Application-Exercise.md) | [Next](./51_Django-Views-and-URLs-Overview.md) \ No newline at end of file diff --git a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/51_Django-Views-and-URLs-Overview.md b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/51_Django-Views-and-URLs-Overview.md new file mode 100644 index 0000000..e373037 --- /dev/null +++ b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/51_Django-Views-and-URLs-Overview.md @@ -0,0 +1,29 @@ +# 51. Django - Views and URLs Overview + +
+ Slides: 51. Django - Views and URLs Overview + +

+ + + + + + + + + + +

+ +
+ +# Resources for this lecture + + +- [Slides: 07-Django-Views,Routing,URLs.pdf](https://python-ds.s3.us-west-1.amazonaws.com/Django-4-and-Python-Full-Stack-Developer-Masterclass/resources/07-Django-Views%2CRouting%2CURLs.pdf) + + +--- + +[Previous](./50_Project-Application-Exercise-Solution.md) | [Next]() \ No newline at end of file diff --git a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/Readme.md b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/Readme.md index 1472243..d051d7e 100644 --- a/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/Readme.md +++ b/Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/Readme.md @@ -44,10 +44,10 @@ Learn the entire technology stack to create beautiful and responsive websites wi
Section 9: Django - Views, Routing, and URLs - - [48. ]() - - [49. ]() - - [50. ]() - - [51. ]() + - [48. Introduction to URLs, Views, and Routing](48_Introduction-to-URLs-Views-and-Routing.md) + - [49. Project Application Exercise](49_Project-Application-Exercise.md) + - [50. Project Application Exercise - Solution](50_Project-Application-Exercise-Solution.md) + - [51. Django - Views and URLs Overview](51_Django-Views-and-URLs-Overview.md) - [52. ]() - [53. ]() - [54. ]() @@ -63,6 +63,47 @@ Learn the entire technology stack to create beautiful and responsive websites wi - [59. ]()
+
+ Section 11: Django - Models, Database, and Queries + + - [69. ]() + - [70. ]() +
+ +
+ Section 12: Django Admin + + - [82. ]() + - [83. ]() +
+ +
+ Section 13: Django Forms + + - [87. ]() + - [88. ]() +
+ +
+ Section 14: Django Class Based Views + + - [94. ]() + - [95. ]() +
+ +
+ Section 15: User Authentication and Sessions + + - [102. ]() + - [103. ]() +
+ +
+ Section 16: Django Linode Deployment + + - [111. ]() + - [112. ]() +
## Requirements diff --git a/README.md b/README.md index a14b97e..6ca969e 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ - [Python and Django Full Stack Web Developer Bootcamp](Curricula/Python-and-Django-Full-Stack-Web-Developer-Bootcamp/README.md) -- [Django 4 and Python Full-Stack Developer Masterclass](Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/README.md) +- [Django 4 and Python Full-Stack Developer Masterclass](Curricula/Django-4-and-Python-Full-Stack-Developer-Masterclass/Readme.md) - [Python Django, Aiohttp Workshop: Cooking Secret Note service](Curricula/Python-Django-Aiohttp-Workshop-Cooking-Secret-Note-service/README.md) diff --git a/codebase/django-4/08-Introduction-to-Django/my_site/my_app/urls.py b/codebase/django-4/08-Introduction-to-Django/my_site/my_app/urls.py index c486297..6102cac 100644 --- a/codebase/django-4/08-Introduction-to-Django/my_site/my_app/urls.py +++ b/codebase/django-4/08-Introduction-to-Django/my_site/my_app/urls.py @@ -2,5 +2,5 @@ from . import views urlpatterns = [ - path('', views.index, name='index'), + path('', views.index, name='index'), # /my_app --> my_app/urls.py ] \ No newline at end of file diff --git a/codebase/django-4/08-Introduction-to-Django/my_site/my_site/settings.py b/codebase/django-4/08-Introduction-to-Django/my_site/my_site/settings.py index 8e9ccdf..d5ddd1b 100644 --- a/codebase/django-4/08-Introduction-to-Django/my_site/my_site/settings.py +++ b/codebase/django-4/08-Introduction-to-Django/my_site/my_site/settings.py @@ -37,7 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'my_app' + ] MIDDLEWARE = [ diff --git a/codebase/django-4/08-Introduction-to-Django/my_site/my_site/urls.py b/codebase/django-4/08-Introduction-to-Django/my_site/my_site/urls.py index c63ee07..f0a46d2 100644 --- a/codebase/django-4/08-Introduction-to-Django/my_site/my_site/urls.py +++ b/codebase/django-4/08-Introduction-to-Django/my_site/my_site/urls.py @@ -18,7 +18,7 @@ from my_app import views urlpatterns = [ - path('', views.index, name="index"), + # path('', views.index, name="index"), path('my_app/', include('my_app.urls')), # /my_app --> my_app/urls.py path('admin/', admin.site.urls), ] \ No newline at end of file