loading...

Its Prime Media, a website built completely with Django

amartyadev profile image Amartya Gaur ・3 min read

Website Screenshot

While people are quickly switching over to MEAN stack, MERN stack, MEVN stack, and what not? Django still is a very powerful framework for web development and let's not forget the plain and simple HTML, CSS, Bootstrap, and Vanilla JS.

The combination of Django and Bootstrap templates are a very good way to make a good looking fully mobile-friendly website, Its Prime Media is a great example of that.

About the website

Its Prime Media is a global media brand that enables people to stay updated and informed with all the latest happenings around the world. They curate, aggregate, and convene the latest articles about News, Movies, Lifestyle, Millionaires, Fashion, and Technology.

They as a media platform recognize their purpose-driven responsibility to amplify stories and voices of the general public that compel change and ensure that each person is heard via citizen journalism.

Its Prime Media is also home to creative people for showcasing their work to millions of users and also aims to provide employment opportunities to them.

Latest articles

Get the latest updates that matter, read data aggregated from your favorite and trusted sources, and stay updated with all the happenings around the globe.

The voice of people

Be heard. All voices matter at Its Prime Media, you can publish any matters of interest or concern.

Get Paid for your Creativity

Display your works on Its Prime Media, possibly get hired but most importantly get applauded for your work in form of small donations. They are open to fashion designers, photographers, graphic designers, poets, and artists.

How it works?

Since this is a technical blog, this is the section you probably have been waiting for :)

If you go and look at the website, you will be able to notice that the server automatically picks your country and displays the articles filtered on your country (currently only the USA, UK, and India are supported). If you want them to extend support to your country, you can always contact them. This is handled by geoIP2.

def get_client_ip(req):
    x_forwarded_for = req.META.get("HTTP_X_FORWARDED_FOR")
    if x_forwarded_for:
        ip = x_forwarded_for.split(",")[0]
    else:
        ip = req.META.get("REMOTE_ADDR")
    return ip

def get_current_country(request):
    current_ip = get_client_ip(request)
    logger.info(f"Recognized IP: {current_ip}")

    try:
        geoIpObject = GeoIP2()
        current_country = geoIpObject.country(current_ip)["country_name"]
        logger.info(f"Recognized Country : {current_country}")

    except AddressNotFoundError:
        current_country = "United States"

    return current_country
Enter fullscreen mode Exit fullscreen mode

The website gets updated every three minutes, gathering data from major sources from those three countries, that is handled using Celery and background asynchronous tasks.

@shared_task
def periodic_update(feed_id):
    feed = get_object_or_404(Feed, id=feed_id)
    urls_in_feed = sc.get_urls_from_feed(feed.url)
    for url in urls_in_feed:
        try:
            UrlsForFeed.objects.create(
                url=url,
                feed=feed
            )
            logger.info("Getting latest content now")
            NewsArticle.objects.create(...data)                
            logger.info(f"Done updating the article titled : {data['title']}")
        except IntegrityError as error:
            logger.info("Skipping this article")
            logger.debug(f"Encountered an Integrity error {error}")
            pass
Enter fullscreen mode Exit fullscreen mode

This task gets added as soon as a new source is added.

User management is pretty much automatic except for an added profile and email verification.

Since the website provides its users with an opportunity to write their own content and get it published, it calls for a rich text uploading feature, which can be very easily added using ckeditor.

Conclusion

What I wanted to show with this blog is that making powerful websites completely with Django is fast, easy, and completely doable, while MEAN, MERN, MEVN have their advantages, Django can also handle async with extensions (this might change to inbuilt support soon). Another option is to use the DVN or DRN or DAN stacks (yeah made them up just now, Django Vue Node or Django React Node or Django Angular Node). The decision is up to you.

PS:-
All Django lovers:
DO CHECKOUT THE WEBSITE

Discussion

pic
Editor guide