Problem with Django multitenant rendering


I have a project called ripso_v2 in python3 and django 1.9 that by now has a couple of apps (created with the startapp and to which I added the file and called "general" and "phva", the main folder of the project and a folder for the templates.

phva /

from django.conf.urls import include, url
from django.views.generic.base import TemplateView
from django.conf import settings
from phva.views import planear

app_name = 'phva'
urlpatterns = [
    url(r'^inicio$', planear.inicio, name='phva_inicio'),
    url(r'^planear$', planear.planear, name='phva_planear'),

ripso_v2 /

from django.conf.urls import url, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth import views
from django.views.generic.base import TemplateView


urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # solo en servidor de desarrollo

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name='publico/index.html'), name='home'),

    url(r'^login/$', views.login, {'template_name':'login.html'}, name='login'),
    url(r'^logout/$', views.logout, {'next_page':'login'}, name='logout'),
    url(r'^cambiar-pass/$', views.password_change, {'template_name':'cambiar-pass.html', 'post_change_redirect':'login'}, name='cambiar_pass'),

    url(r'^general/', include('general.urls')),
    url(r'^perticular/', include('phva.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I had to update to a href="{% url 'phva:phva_inicio' %}" since it is something of django 1.9


phva / views /

from django.http import Http404
from django.shortcuts import redirect, render, render_to_response, get_list_or_404
from django.contrib.auth.decorators import login_required
from phva.forms import *

from ripso_v2.utilities import *

def inicio(request):
    return render(request, 'phva_inicio.html')

def planear(request):
    return render(request, 'phva_planear.html')
asked by Diana Carolina Hernandez 03.02.2016 в 16:07

1 answer


This is not a definitive answer to your problem since you have run into a new problem, however, I think this would not look good as a comment and helps you understand your initial problem with URLs.

According to the release notes of Django 1.9 with respect to URLs :


The application namespace can now be set using an app_name attribute on the included module or object. It can also be set by passing to 2-tuple of (,) as the first argument to include ().

That is, defining the app_name in the of your app, you are already defining the namespace :

app_name = 'particular'
urlpatterns = [
    url(r'^inicio$', planear.inicio, name='acc_inicio'),
    url(r'^planear$', planear.planear, name='acc_planear'),

This means that when using the url tag in your template you need to also pass the namespace :

<a href="{% url 'particular:acc_inicio' %}">Inicio</a>

Otherwise, Django will show you the error NoReverseMatch of your original question by not finding the pattern.

It is also possible to use the previous form using the namespace parameter in the% function call% co:

urlpatterns = [
    # ...
    url(r'^particular/', include('particular.urls', namespace='particular')),
    # ...

Both methods are valid.


Includes the new error to find the solution

answered by 03.02.2016 / 17:10