N
N
newvasyuki2020-11-17 18:16:40
Django
newvasyuki, 2020-11-17 18:16:40

How to generate full url in Celery task?

There is a celery task (django project), where the pk of the model is transferred and further manipulations are already performed in it. The problem is that in the task you need to form the full url. get_absoulute_url is not suitable (already in use). There is also request.build_absolute_uri(), but this object is naturally not available in the task. Googled it, the options are:

  1. Use the sites framework in django: collect from get_current_site and reverse
  2. Modify the taxi parameters, form the url in the view (request.build_absolute_uri()) and pass it to the task
  3. Add the domain to settings as a variable and there already collect from it and reverse


I don't really like all these options, because they are some kind of crutches, and the first one is also an overkill for the task.
What is the standard solution (best practices) for this task? (maybe i'm missing something)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-11-17
@bacon

The 2nd option, for sure, except from request, it’s impossible to find out, so I would pass the host to the task, and I would already collect the full url in it. Well, the 3rd one with settings will also pull, but I was always embarrassed that you can set at least something there that is different from reality.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question