K
K
Kirill Gorelov2019-04-24 11:18:52
Django
Kirill Gorelov, 2019-04-24 11:18:52

A couple of Python questions about plugins?

Guys, hello.
Relatively not long ago I "moved" from php to python and of course, the first thing that catches your eye is the connection of modules.
I am writing training applications in django and it happens that a huge number of modules / decorators / classes and so on accumulate in one view.
Even if this view is divided into several small ones, a decent number of modules still remain. After php is not customary.
And actually the first question, is it possible to somehow make everything in django "auto-connect" itself??
I have an idea, this is to make a separate file, put all the modules that are needed there and just include one line in all files, but it seems to me that this will slow down the work.
And the second question. How best to connect modules.
1c.

from django.contrib.auth.models import User
from django.shortcuts import render, redirect

def main1(request):
    return render(request, 'client/client.html', {})

def main2(request):
    return render(request, 'client/client.html', {})

2c.
from django.shortcuts import render, redirect
def main(request):
    return render(request, 'client/client.html', {})

from django.contrib.auth.models import User
def main(request):
    #тут используется User
    return render(request, 'client/client.html', {})

It doesn't matter what it says, what matters is the example. That is, before each function, call the desired module.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2019-04-24
@sim3x

Is there a way to make everything in django "auto-connect" itself??
https://www.python.org/dev/peps/pep-0020/
Explicit is better than implicit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question