6

I have two Pythonapplications 'frontend' and 'fv'. in my fv app is my tasks.py file and in my frontend app is my views.py file to render my views.

Now I have a view where I can choose some parameters get these with request.POST. and now I'd like to call a a task method FunctionRDynamic and pass the parameters from my view form.

Method in views.py:

if request.method == 'POST':
        form1 = dataproviderInstrumentForm(request.POST)
        form2 = dynamicTimeseriesForm(request.POST)

        if form1.is_valid() or form2.is_valid(): 
            filters = form2.cleaned_data['filter']
            estimator = form2.cleaned_data['estimator']
            windowSize = form2.cleaned_data['windowSize']

            FunctionRDynamic.delay(estimator, windowSize, timeseries)

FunctionRDynamic is my method in the tasks.py file in the oder application, but this method will not execute.

For my tasks I use celery. All is written in Python and I use Django as mvc framework.

Does anyone have suggestions?

1 Answer 1

16

From what I have understood here's the solution. While defining celery tasks do this:

@celery.task
def file_transfer(password, source12, destination):
    # Do stuffs with paramters

Now in your views.py do this:

def test(View):
    # Get the data from post
    if request.method == 'POST':
        name = request.POST['name']
        # And get all the variable you need for the tasks

        # Now call the task like this
        file_transfer.delay(name, 'test', 'test')
Sign up to request clarification or add additional context in comments.

4 Comments

thx for the fast answer, if i call the task without .delay - as your solution, i get a "Unable to connect" error in my browser and i lost the connection.
Yes, you have to use task_name.delay. Sorry for the typo.
Two questions: Do you have celery running and do you have message transfer backend setup? Run the celery in DEBUG mode: ./manage.py celeryd -lDEBUG and tell me what error do you see.
it was my fault, because i haven't started the workers. thx for your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.