Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc Django import finder bugs #3824

Conversation

ciarancourtney
Copy link

Will probably fix #2281 among other issues where Django <1.8 settings were assumed, This PR assumes only Django >=1.8 is supported.

* Cannot use hasattr on a dict
* split settings on '.settings' and assume first part is abs app module
…LED_APPS

* Also remove long defunct TEMPLATE_CONTEXT_PROCESSORS & TEMPLATE_LOADERS
@karthikdesai
Copy link

Hi i pulled in your PR and rebased it on top of pyinstaller/develop. I faced some issues, i have uploaded a couple of gists.
https://gist.github.com/karthikdesai/5b66480dfb729a05d1f5a98499ddfc80

This log is when i tried to run the manage.exe runserver
https://gist.github.com/karthikdesai/f946ee49c17d42e0209e792dbf8340bf

Did you face this? I am on Django 1.11, Python 2.7

@ciarancourtney
Copy link
Author

Hi i pulled in your PR and rebased it on top of pyinstaller/develop. I faced some issues, i have uploaded a couple of gists.
https://gist.github.com/karthikdesai/5b66480dfb729a05d1f5a98499ddfc80

I saw this too, presumably safe to ignore if not using django.contrib.gis

This log is when i tried to run the manage.exe runserver
https://gist.github.com/karthikdesai/f946ee49c17d42e0209e792dbf8340bf

Did you face this? I am on Django 1.11, Python 2.7

Yes, templatetags are another issue, I resolved this by explicitly registering under libraries as mentioned here In general this a better practice rather then relying on Django's register magic.

But other than that, I'd recommend using your own hook-django.py as a hootpath (you'll need to delete the package version for this to work (theres an open issue for this)

@karthikdesai
Copy link

@ciarancourtney Sorry was off for a couple of days. Will try it now
But what version of Django are you using? The same 1.11 or 2.1? And if 2.1, is it Python 3.5?

@ciarancourtney
Copy link
Author

Using Django 1.11 on Python 3.6, don't think it will make much difference

@karthikdesai
Copy link

Ah okay! I did fix by adding a little more data to my .spec file.
'django.template.defaulttags', 'django.template.loader_tags', 'django.middleware.clickjacking', 'django.middleware.security', 'django.template.loaders.filesystem'
Now i have got TemplateDoesNotExist at /xxx/ error :( and i see that pyinstaller does not pack my app really well. It is missing all the static and template folders for my app.
And when i try to load the admin page, i get,

TemplateSyntaxError at /admin/login/
'i18n' is not a registered tag library. Must be one of:

After 'Must be one of:' it is blank. I think i am missing more hidden imports here.
The pyinstaller magic for you or did you have to change anything else?

@ciarancourtney
Copy link
Author

Look at #1717 (comment) for i18n error

And you need to bundle your templates as data files. See helper function collect_system_data_files

@karthikdesai
Copy link

@ciarancourtney Okay it did start to work on python3.5. I still had the bug in python2.7 weirdly!
Thank you for your help! :)

@NissanAloni
Copy link

I also have couple of fixes to django_import_finder.py to support django 2.0+
how can I contribute them?

@saneletm
Copy link

saneletm commented Jun 11, 2019

I am using django 1.11 with Python 2.7.16 and PyInstaller 3.2, getting this error when running my app:

[11/Jun/2019 15:50:25] INFO [webservice:188] service is starting from main...
[11/Jun/2019 15:50:25] INFO [webservice:72] Launching apache and solr monitor thread.
[11/Jun/2019 15:51:26] ERROR [webservice:85] Exception in Run: Traceback (most recent call last):
File "site-packages/django/core/handlers/base.py", line 215, in _get_response
File "site-packages/django/template/response.py", line 107, in render
File "site-packages/django/template/response.py", line 82, in rendered_content
File "site-packages/django/template/response.py", line 64, in resolve_template
File "site-packages/django/template/loader.py", line 48, in select_template
File "site-packages/django/template/backends/django.py", line 39, in get_template
File "site-packages/django/template/engine.py", line 162, in get_template
File "site-packages/django/template/engine.py", line 132, in find_template
File "site-packages/django/utils/functional.py", line 35, in get
File "site-packages/django/template/engine.py", line 106, in template_loaders
File "site-packages/django/template/engine.py", line 111, in get_template_loaders
File "site-packages/django/template/engine.py", line 124, in find_template_loader
File "site-packages/django/utils/module_loading.py", line 20, in import_string
File "importlib/init.py", line 37, in import_module
ImportError: No module named loaders.cached

Here are my templates settings:

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [normpath(join(SITE_ROOT, 'templates'))],
'OPTIONS': {
"debug": False,
"context_processors": (
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
'options.context_processors.system_notifications_context',
'versioning.context_processors.versioning',
'xdv.context_processors.launch_client_url',
)
},

}

]

I have tried to add the import to my PyInstaller hook file for hiddenimports, but doesn't seem to be helpful:

hiddenimports = []
....
hiddenimports += collect_submodules('django.template.loaders.cached')
....

I think for some reason PyInstaller is having a hardtime locating django/temaplate/loaders/ module.
Any idea how I can fix this? I'll greatly appreciate your help. Thanks!

@Legorooj
Copy link
Member

Stale

@Legorooj Legorooj closed this Feb 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Django 1.10 compatibility
5 participants