M
M
maddread2015-12-21 13:34:28
Django
maddread, 2015-12-21 13:34:28

What are the capabilities of views in Django and is it possible to use python code in them?

I am learning Django and I have a question. One way or another, everything in the tutorials is tied to data models, views, urls, etc. How can I use arbitrary code in django, for example in the same view page? Is there something similar to inserts like in jsp or php?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
sim3x, 2015-12-21
@sim3x

You can't use python directly in djangotemplates

P
Peter, 2015-12-21
@petermzg

Django is an MVC model (Model-View-Controller)
View is templates, page template.
Controller is executable code, here you can write whatever you want in python and prepare all the necessary data to be displayed in View.
This approach allows the programmer to do his own thing, and the designer / layout designer to do his own.

E
Evgeny Maltsev, 2015-12-21
@hellpirat

https://docs.djangoproject.com/en/1.9/ref/template...

A
Anton, 2015-12-23
@widestream

Why directly? Write a tag and use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question