27
loading...
This website collects cookies to deliver better user experience
Django is a Python-based free and open-source web framework that follows the model-template-views architectural pattern. — Wikipedia
The View updates the Controller with the action, i.e. the click button, and data, which is the post itself.
The Controller transfers this information to the Model, which saves the post in the DB.
The Model responds to the Controller with the new-post data.
The Controller sends the View an object that has all the data it needs in order to show the user a pop-up message saying “your post was published successfully”, and our user see their new post on their page.
![]() |
---|
MVC Facebook post example |
![]() |
---|
Now you know which operating system I worked on while creating this blog post ;) |
python
(and Enter). No response means that you don’t have it installed, otherwise, you will see the version number. For some, including myself, typing python
won’t work, but typing py
does.py -m pip --version
in the Windows Command Prompt or python -m pip --version
in the Unix/Mac OS Terminal.py -m pip install django
in Windows or python -m pip install django
in Unix/Mac OS. Hopefully, you will see it finish with “Successfully installed Django-3.2 asgiref-3.3.4 pytz-2021.1 sqlparse-0.4.1”C:\Users\Admin> py
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
3.2
>>>
encyclopedia/urls.py: path("", views.index, name="index")
.
First of all, path= ""
means it’s the home page.
Now, see views.index
? It indicates that the next step in our trip is the views.py file.
def index(request):
return render(request, "encyclopedia/index.html",
{
"entries": util.list_entries()
}
)
{% for entry in entries %}
def list_entries():
"""
Returns a list of all names of encyclopedia entries.
"""
_, filenames = default_storage.listdir("entries")
return list(sorted(re.sub(r"\.md$", "", filename)
for filename in filenames if
filename.endswith(".md")))