Forums

Importing python-slugify to django app model

Hello, I'm getiing an 403 error when trying to import slugify to my django app. On my local machine i use:

from slugify import slugify

as stated in the python-slugify documentation and it works as expected. However this error occures when using the same script, (mind that I'm able to import slugify directly in the python console), my error log says:

2017-06-05 15:11:20,467: Error running WSGI application
2017-06-05 15:11:20,468: ModuleNotFoundError: No module named 'slugify'
***
2017-06-05 15:11:20,472:   File "/***/models.py", line 13, in <module>
2017-06-05 15:11:20,472:     from slugify import slugify
2017-06-05 15:11:20,472: ***************************************************
2017-06-05 15:11:20,472: If you're seeing an import error and don't know why,
2017-06-05 15:11:20,473: we have a dedicated help page to help you debug: 
2017-06-05 15:11:20,473: https://help.pythonanywhere.com/pages/DebuggingImportError/
2017-06-05 15:11:20,473: ***************************************************

This doesn't work either (ModuleNotFoundError: No module named 'slugify'):

 import slugify

Couldn't find a solution here or on google, would love to get a solution. Thanks in advance!

It looks like your website is using a virtualenv, which means that it only has access to packages that you're installed into that virtualenv. Are you sure slugify has been installed?

...to check, click the "Start a console in this virtualenv" link on the "Web" tab, and run

pip show python-slugify

If that gives an empty result, you need to install it in the same console, by running

pip install python-slugify

...then reload your web app.

Yep, that did it, thanks!

Great!