[Fixed]-Django turn url to image / views

1👍

If you want to have a list of the object Blog, then you can do it in several cases. The first one is generic view ListView:

from django.views.generic.list import ListView
from yourapp.models import Blog

class BlogListView(ListView):
    model = Blog

In that case your urls will looks like that:

from django.conf.urls import url
from yourapp.views import BlogListView
urlpatterns = [
    url(r'^$', BlogListView.as_view(), name='blog-list'),
]

and template:

{% blog in object_list %}
   <img src="{{blog.photo}}">
{% endfor %}

Here is link on it

the other way is creating request:

from django.shortcuts import render
from yourapp.models import blog
def blogListView(request):
  blog_list = Blog.objects.all()
  return request(render, 'path/to/your/template.html', {'blog_list':blog_list})

In that case your url will look like this:

url(r'^$', views.blogListView, name='blog-list'),

Your template:

{% for blog in blog_list%}
   <img src="{{blog.photo}}">
{% endfor %}

So you just have add <img src="{{blog.photo}}"> in your template

Leave a comment