I have a project called ripso_v2 in python3 and django 1.9 that for now has a couple of apps (created with startapp and to which I added the file urls.py and forms.py) called "general" and "phva", the main folder of the project and a folder for the templates.
phva/urls.py
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/urls.py
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
admin.autodiscover()
urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # solo en servidor de desarrollo
urlpatterns = [
url(r'^admin/', admin.site.urls),
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 upgrade to a href="{% url 'phva:phva_inicio' %}"
since it's something from django 1.9
Mistake
phva/views/plane.py
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 *
@login_required
def inicio(request):
return render(request, 'phva_inicio.html')
@login_required
def planear(request):
return render(request, 'phva_planear.html')
This is not a definitive answer to your problem as you have run into a new problem, however I think this would not look good as a comment and helps to understand your initial problem regarding URLs.
According to the Django 1.9 release notes regarding URLs :
That is, by defining the
app_name
inurls.py
your app, you are already defining thenamespace
:This means that when using the tag
url
in your template you need to also pass thenamespace
:Otherwise, Django will show you the error
NoReverseMatch
from your original question of not finding the pattern.It is also possible to use the above way using the parameter
namespace
in the function callinclude
:Both methods are valid.
Note:
Include the new error to find the solution