You can copy and paste each of the following directly into the terminal:
$ mkvirtualenv -p $(which python3.5) django_basic_views
$ pip install -r requirements.txt
You can now run the development server:
$ make runserver
The structure of the whole Django project is built for you. Your job is to implement the views that are under django_basic_views/views.py
, and complete the proper URLs in django_basic_views/urls.py
.
Running the development server with $ make runserver
, you'll be able to test your views in the browser by pointing to http://localhost:8080/<path-for-your-view>
, or if you're using Cloud9 then the URL will look like https://<project-name>-<your-c9-username>.c9users.io/<path-for-your-view>
C9 should provide you a link when you run the server, just click through the warning.
Implement a simple view under the /hello-world
URL path that returns a 'Hello World' string. Use the function HttpResponse()
imported from Django.
In order to check if you've successfully completed this task you can run the following command. Check code inside tests.py
if you want to see how a (simple) test is written in Django.
$ make test
Implement a view under the /date
URL path that returns a string with current date using the datetime library.
Implement a view under the /my-age/<year>/<month>/<day>
URL path that returns a string with the format: "Your age is X years old" based on given /year/month/day that come as parameters.
Implement a view under the /next-birthday/<birthday>
URL path where birthday
parameter is a string with the format "YYYY-MM-DD". The view should calculate the amount of days until next birthday and return a string with the format "'Days until next birthday: XYZ'"
Implement a view under the /profile
URL path that renders the profile.html
template. You'll need to use the render()
function imported from Django. Also make sure to check what variables the template is going to look for and provide render()
with a context dictionary that has those variables as keys (you can choose whatever you'd like for the values).
The goal for this task is to practice routing between two URLs. You will have:
/authors
which renders a list of Authors (the template is provided already)/author/<authors_last_name>
which renders the detail view for each given author, using the AUTHORS_INFO context dictionary provided to you.
The first view just needs to render the given authors.html
template.
Second view has to take the authors_last_name
provided in the URL, look for for the proper author info in the dictionary, and send it as context while rendering the author.html
template. Make sure to check that the variables the author.html
template is looking for match the keys of the context dictionary you are sending.