Redirect center with Django

I am interested to create a website using the latest Django version (> 5.0 when is released) to obtain the following:

  • I will create QR codes that will point to: mydomain dot com/c1p1i1 or mydomain dot com/c1p2i1.
  • Some of them should be redirected to external addresses (extern to and some others should be redirected to my homepage (mydomain dot com).
  • For all the requests (either redirected forward or to my homepage) I want to create a statistic to know how many requests I have received or to integrate google analytics and see statistics.

I have an idea how is more efficient to do it but I am interested if somebody has done something similar and could give me some hits to make these redirects really fast and also catch all the metadata for statistics.


How I would do this would depend a lot upon the specific details. How many different QR codes (urls) are involved? How many external sites?

For the ones referencing internal resources (inside, how may URLs are being referenced? Is it important that they redirect to your home page, or can it just resolve to your homepage?

If the number of URLs (QR codes) is relatively reasonable and bounded, I’d do this within nginx - Django wouldn’t even be involved here. You’ll have access to the individual references in your nginx logs.

Thank you for reply.

  • I would say most probably between 200 and 300 QR codes with different parameters
  • Around 100 external addresses (outside of
  • For the internal resources, I want to have only one page, my homepage. Is like a public personal profile which should be seen when someone accesses mydomain or scans a QR code that is intended to go internal.
  • Redirect or Resolve, no preference, depends which option is faster and safer.
  • Nginx would also be a possibility but needs more work to handle the statistics and by using Django and Django admin might sound easier to implement this (not sure, just a hunch)

I might also decide in the future to offer more functionality for my website (besides the homepage with the personal profile) and this is why I tend to use Django not nginx as a solution to this particular problem.

That alone makes the nginx-based solution impractical. (It could be done, but I wouldn’t want to have to manage it.)

Notwithstanding the previous comment, not really. There are a lot of resources already existing to provide analysis of web server logs. This is a well-covered field among those who manage web servers.

If I had to handle something like this, I’d first do something like define the urls such that nginx could easily determine whether it’s an internal or external reference. (It doesn’t mean I necessarily am going to take advantage of that information yet, but I’d be inclined to believe it may have value.)

I’d then create middleware that would examine the incoming URL to short-circuit the normal process for external links. I’d send the request to a celery task and return the redirect. (I don’t want the redirect to have to wait for the request to be saved to the database.) Actually, I would do that logging in celery for the internal links coming in from QR code URLs as well.

Good idea with the middleware and celery. I might even search for something simpler than celery.

What could be the advantage to setup nginx to understand if it is an internal or external reference?

Depending upon a number of different factors, you might want to consider making the external URL handler a separate app within your project. Have one app that only handles external URLs and a separate app that handles the internal URLs.

It’s an option for somewhat simplifying your application. Instead of having the middleware making that determination, it still allows nginx to do what it does best, reducing the latency and load on your application. (Adding the middleware is going to have some effect on your entire project - even for pages not coming from QR-code-URLs. Again, this may not be an issue at all for you.)

There’s not a whole lot that would be simpler than celery using redis as the message broker - at least not an option that is reliable and performant.

Thank you for the suggestions. They have truly helped me in shaping the structure of my project.