python - How can I change this div with same search_key when I click next button? -


this views.py retrieve 6 image urls instagram.first time ok how can change shown 6 images in home.html file(that retrieve 6 new images) when click next button?

def home(request):     trends  = []     if request.method == 'post':           if request.post.get('q'):             search_key = request.post.get('q').replace(" ","")              getimagefrominstagram(search_key)         else:             search_key = ''         veriler = hashtags.objects.values_list('hashtag',flat=true)         line = hashtags(hashtag=search_key,trends=search_key,image_url=tagurl)         line.save()         return render(request, "home.html", {'trends':trends,'urls':urls,'hashtags':veriler})  def getimagefrominstagram():     tagurl = 'https://api.instagram.com/v1/tags/'+ search_key +'/media/recent?client_id=hidden security'     q = requests.get(tagurl).json()     urls = [ q['data'][i]['images']['standard_resolution']['url'] in range(6)]      return urls    

end home.html

<div class="col-md-8 timeline">     {%for image_url in urls%}         <img src="{{image_url}}">     {% endfor%} </div> <button type="submit" name="submit" class="btn btn-primary btn-lg btn-block">next</button> 

your form

<form action="{% url 'home' %}?next_url={{ next_url }}">    <div class="col-md-8 timeline">    <input name="q" type="text">    {%for image_url in urls %}        <img src="{{image_url}}">    {% endfor%}    </div>    <button type="submit" class="btn btn-primary btn-lg btn-block">next</button> </form> 

your views.py

def home(request):     trends  = []     if request.method == 'get':           q = request.get.get('q', '').replace(" ","")          next_url = request.get.get('next_url', none)         urls, next_url = getimagefrominstagram(q=q, next_url=next_url)         # .. other code         return render(request, "home.html", {              'trends': trends,              'urls': urls,               'next_url': next_url,         })  def getimagefrominstagram(q="", next_url=none):     if next_url not none:         res = requests.get(next_url).json()         urls = [ res['data'][i]['images']['standard_resolution']['url'] in range(6)]                        else:             tagurl = 'https://api.instagram.com/v1/tags/'+ q+'/media/recent?client_id=hidden security'         res = requests.get(tagurl).json()         urls = [ res['data'][i]['images']['standard_resolution']['url'] in range(6)]       next_url = res['pagination']['next_url']     return urls, next_url 

but didnot test it.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -