Bahus / uwsgi_tasks

Asynchronous tasks management with UWSGI server
MIT License
95 stars 15 forks source link

Cant access Django Templates #3

Closed chokosabe closed 9 years ago

chokosabe commented 9 years ago

I have a django app. I keep getting a TemplateDoesNotExist error for this:

from django.template import loader template = loader.get_template('path/to/tempate/summary.html')

Also, importing django settings seems to result in null..

i.e from django.conf.settings comes up null....

The same line in a celery job seems to work fine and no issues when using the @task decorator.

Thanks

chokosabe commented 9 years ago

To add more detail:

django.template.base.TemplateDoesNotExist: email_engine/data_methods/summary.html raise TemplateDoesNotExist(name) File "/home/vagrant/env/local/lib/python2.7/site-packages/django/template/loader.py", line 136, in find_template template, origin = find_template(template_name, dirs)

Bahus commented 9 years ago

Hello! Thank you for reporting. The issue is related to working dir of spooler process - actually it user current spooler folder as working directory, so Django can't find valid templates directory, since it's relative to the real project directory (not spooler directory).

Could you please install try new release via pip line: pip install git+git://github.com/Bahus/uwsgi_tasks.git@v0.6 and check if the issue still persist?

chokosabe commented 9 years ago

Hi Bahus, yes, its still an issue with version 0.6. Exact same error with finding the templates... I think this is a general issue whenever you have a library that's being imported lazily... i.e django settings....

Bahus commented 9 years ago

Hi @chokosabe, I'm still thinking about working directory or PYTHONPATH-related issue. Spooler should initialize Django environment in the same way as usual UWSGI worker does it. By the way what is version of UWSGI you are using?

Could you please also do the following:

Open local file on this line: https://github.com/Bahus/uwsgi_tasks/blob/master/uwsgi_tasks/tasks.py#L65 and add some code to the begging of the manage_spool_request function (for debug reasons):

def manage_spool_request(message):
    import os, sys
    from django.conf import settings
    print 'Working dir:', os.getcwd()
    print 'PYTHONPATH:', sys.path
    print 'CONFIGURED', settings.configured
    try:
        print settings.LOGGING
    except:
        print 'EXCEPTION'
    settings.configure()
    print settings.DEBUG
    ...

Then reproduce the problem and let me know the output. Is channel package (channel.helpers.update_redis_channels) located somewhere in shown PYTHONPATH?

Bahus commented 9 years ago

Hello @chokosabe! I have added some detail to documentation with working configuration: https://github.com/Bahus/uwsgi_tasks#project-setup please check it, since it may help to configure the package properly.