In fact that was the first place in which I defined the urls of my
application, exactly as shown below, but it did not work.
*project_name/**project_name/urls.py*
# MEZZANINE'S URLS
# ----------------
# ADD YOUR OWN URLPATTERNS *ABOVE* THE LINE BELOW.
# ``mezzanine.urls`` INCLUDES A *CATCH ALL* PATTERN
# FOR PAGES, SO URLPATTERNS ADDED BELOW ``mezzanine.urls``
# WILL NEVER BE MATCHED!
# If you'd like more granular control over the patterns in
# ``mezzanine.urls``, go right ahead and take the parts you want
# from it, and use them directly below instead of using
# ``mezzanine.urls``.
url("^", include("mezzanine.urls")),
*url(r'^ingredients/', include("apps.ingredients.urls")),*
However if I define it in the same file but before any other definition
works well
# Add the urlpatterns for any custom Django applications here.
# You can also change the ``home`` view to add your own functionality
# to the project's homepage.
urlpatterns = [
*url(r'^ingredients/', include("apps.ingredients.urls")),*
]
urlpatterns += i18n_patterns(
# Change the admin prefix here to use an alternate URL for the
# admin interface, which would be marginally more secure.
url("^admin/", include(admin.site.urls)),
)
Ok, the important thing is that it works without altering the structure of
the project. Thank you very much for the help.
Il giorno sabato 9 settembre 2017 21:52:36 UTC+2, Rainell Dilou Gómez ha
scritto:
>
> I created a view for my model, with the corresponding urls and template
> files. Then, in the admin panel, I have created a Rich text page,
> specifying the same URL (ingredients) defined in urlpatterns. Mezzanine
> ignores the view, displays the template but does not pass the context.
> Please help, how can I solve that?
>
> *models.py*
> from django.db import models
> from mezzanine.pages.models import Page
> from django.utils.translation import ugettext_lazy as _
>
> class Ingredient(Page):
> name = models.CharField(max_length=60)
> information = models.TextField(null=True, blank=True, verbose_name=_(
> "Description"))
>
> *views.py*
>
> from django.shortcuts import render
> from .models import Ingredient
>
> def ingredients(request):
> ingredients = Ingredient.objects.all().order_by('name')
> return render(request, 'pages/ingredients.html', {'ingredients':
> ingredient
>
>
>
> *urls.py*
> from django.conf.urls import url
> from .views import ingredients
>
> urlpatterns = [
> url("^$", ingredients, name="ingredients"),
> ]
>
> *NOTE: *I have also tested with TemplateResponse and it also did not work:
> from django.template.response import TemplateResponse
> from .models import Ingredient
>
> def ingredients(request):
> ingredients = Ingredient.objects.all().order_by('name')
> templates = ["pages/ingredients.html"]
> return TemplateResponse(request, templates, {'ingredients':ingredients
> })
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.