D
D
Dominik092016-11-06 09:59:16
Django
Dominik09, 2016-11-06 09:59:16

How to force Django to include multiple modules when loading the main page?

Perhaps I didn't formulate the problem too tactfully. I'll explain now. A Django site consists of more than 3 modules. In urls.py I connect all of them as it should be through Include, I assign a name. And here's the problem, I need to load several modules at once when loading the main page of the site. Now the work looks like this, for example, I connect the "news" module, where I did not assign any link and, accordingly, when the main page is loaded, it will launch its method, and the "loginapp" user interface module will not work. Authorization and all other necessary functions do not work.

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^loginapp/', include("loginapp.urls", namespace='loginapp')),
    url(r'^publications/', include("publications.urls", namespace='publications')),
    url(r'^', include("news.urls", namespace='news')),
]

Of course, I know that the module with users will work in this case:
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^publications/', include("publications.urls", namespace='publications')),
    url(r'^', include("loginapp.urls", namespace='loginapp')),
    url(r'^', include("news.urls", namespace='news')),
]

but then the "news" module won't work, because Django simply didn't get to it.
So tell me how can I make it so that I can include several django modules. So that when the main page loads, both "loginapp" and "news" work for me?
I will say right away that I tried to run a common method on views at the root of the project.
def main(request):
    return render_to_response('main.html')

Everything worked half way. loginapp gave information that the user is not authorized, but actually authorized, and media files were not loaded in news.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
held, 2016-11-06
@held

It is necessary to connect these modules not in the URL , but in TEMPLATES .
url fulfills only one function. And if I worked out everything, how would the program understand where to insert which block?
In general, you somewhere exiled here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question