Django Meme App

Nilay Paul
2 min readApr 28, 2021

--

Today we will see how to create a meme app in django.

It’s a pretty basic build and a good companion of weather app using weather Api.

We will use “https://meme-api.herokuapp.com/gimme” this end point.

django-admin startproject MEME
cd MEME
python manage.py startapp mymeme

Create a templates folder inside the project.

Project structure
In the installed app list of settings.py of the project add ‘mymeme’ app and in the DIRS[] add ‘templates’

In the project level urls.py add

from django.contrib import adminfrom django.urls import path,includeurlpatterns = [path('admin/', admin.site.urls),path('',include('mymeme.urls'))]

In the app level urls.py use add..

from django.urls import path,includefrom . import viewsurlpatterns = [path('',views.getdata,name="getdata")]

In the views.py of the app add

from django.shortcuts import renderimport requests# Create your views here.def getdata(request):        response=requests.get('https://meme-api.herokuapp.com/gimme').json()        context={              'url':response['url']        }        return render(request,'index.html',context)

In the index.html file add

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Meme App</title><style>.container{display: flex;justify-content: center;}</style></head><body><div class="container"><img src="{{ url }}" alt="Your internet connection may be broken!" style="width: 30%;height:30%;padding:15px;"></div><div class="container"><button style="background-color: aqua;padding:10px;margin:15px;border-radius:5px;cursor:pointer;" onclick="location.href='{% url 'getdata' %}'">Press To Load More</button></div></body></html>

Now run “Python manage.py runserver” command.

And that’s basically it.

Result

Deployed version ->https://reditmemedj.herokuapp.com/

--

--