I have an app with a product loading form for books (Product, Date of publication, file)
After loading it generates its own url ( link )
But when selecting to see all the images, I get the following error:
verimagenes.html
{% extends "vistaprevia/plantilla.html" %}
{% block content %}
<div class="container">
<div class="jumbotron">
<h2>Ver todas las imagenes</h2>
</div>
</div>
<main class="container">
<div class="row" >
<section class="col-12" style="padding:30px; 30px; 230px; 30px;">
{% for productos in productos %}
<a href="{% url 'ver' productos.id %}">
<img src="/media/{{productos.ruta_imagen}}" alt="My Image" width="20%">
</a>
{% endfor %}
</section>
</div>
</main>
{% endblock %}
urls.py
from django.conf.urls import url
from vistaprevia import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^cargar/$', views.cargar_imagen, name='cargar'),
url(r'^(?P<producto_id>\d+)/ver/$', views.ver_imagen, name='ver'),
url(r'^verimagenes/$', views.verimagenes, name='verimagenes'),
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from vistaprevia.models import Producto
from django.shortcuts import redirect
from vistaprevia.forms import CargarForm
from django.http import Http404
from django.shortcuts import render_to_response
#def index(request):
# return HttpResponse("Hola Mundo!.")
def index(request):
contenido = {'nombre_sitio': 'LibrosOnline'}
para_minorista = {'tipo_usuario' : 'minorista' , 'incremento' : '25'}
para_mayorista = {'tipo_usuario': 'mayorista', 'incremento': '10'}
return render(request, 'vistaprevia/index.html', {'contenido':contenido,
'para_minorista' : para_minorista, 'para_mayorista' : para_mayorista})
def cargar_imagen(request):
if request.method == "POST":
form = CargarForm(request.POST, request.FILES)
if form.is_valid():
producto = form.cleaned_data['producto']
fecha_publicacion = form.cleaned_data['fecha_publicacion']
ruta_imagen = form.cleaned_data['ruta_imagen']
newdoc = Producto(producto=producto, fecha_publicacion=fecha_publicacion,
ruta_imagen=ruta_imagen)
newdoc.save()
return redirect("verimagenes")
else:
return render(request, 'vistaprevia/formulario.html', {'form': form})
else:
form = CargarForm()
return render(request, 'vistaprevia/formulario.html', {'form':form})
def ver_imagen(request, producto_id):
try:
producto = Producto.objects.get(pk=producto_id)
except Producto.DoesNotExist:
raise Http404
return render_to_response('vistaprevia/verimagen.html',{
'producto': producto,
'error_message' : "No has seleccionado un producto.",
},content_type=RequestContext(request))
def verimagenes(request):
try:
productos = Producto.objects.all()
except Producto.DoesNotExist:
raise Http404
return render_to_response('vistaprevia/verimagenes.html',{
'productos': productos,
'error_message' : "No has seleccionado un producto.",
},content_type=RequestContext(request))
the help is appreciated