1. Django - Exercise 1 - Create a basic Webpage
Create a basic Django powered webpage. The following are provided:
- 1. Project - Exercise 1
- 2. App - Webpoll
- 3. Models - Question and Choice
- 4. Migrated models
Do the following:
1. In views.py, define a `home` function that accepts a `request` and returns an HttpResponse with the text "Welcome to webpoll home!"
2. In webpoll/urls.py: Import views Create a `urlpatterns`variable. Add a URL with route '' to `views.home` named name='home'. 3. In exercise1/urls.py:
3. In exercise1/urls.py:
Import `include` from `django.urls`.
Create a urlpatterns variable.
Add a path to set the home URL as 'webpoll/'.
Call the `webpoll.urls` using the include function.
Note: To run migrations again, use the in-built command line option by clicking "New Terminal" (">_"), or by clicking "File" -> "New Terminal".
In the IDE, do the following:
1. Click RUN -> INSTALL (to install the necessary packages).
2. Click RUN -> RUN SERVER (to launch Jupyter notebook).
3. Click Preview App.
4. Click RUN -> Tests (to test the application).
Note: To check the functioning of the web page, use:
Answer:
webpoll/urls.py
webpoll/views.py
exercise1/urls.py
Click on the image to see tests:
No comments:
Post a Comment
If you have any doubts, Please let us know.