I want to do some functional tests on my django app. I'm using selenium, tests works but the problem is with static files. The css/js status is not found. My tests is running on localhost:8081. Example bootstrap.css:
<h1>Not Found</h1><p>The requested URL /static/frontend/bootstrap/3.3.0/css/bootstrap.css was not found on this server.</p>
I can't find any information do I have add some extra config for selenium app?
Trackback:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1028, in __call__
return super(FSFilesHandler, self).__call__(environ, start_response)
File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
response = self.get_response(request)
File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1011, in get_response
return self.serve(request)
File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1023, in serve
return serve(request, final_rel_path, document_root=self.get_base_dir())
File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/views/static.py", line 50, in serve
fullpath = os.path.join(document_root, newpath)
File "/home/t/py/django/bid/src/venv/lib/python2.7/posixpath.py", line 77, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
Instead of using LiveServerTestCase from django.test
you can use StaticLiveServerTestCase from django.contrib.staticfiles.testing
.
Notice not just the different class-name, but also the different module-name:
from django.test import LiveServerTestCase # ^-- vs --v from django.contrib.staticfiles.testing import StaticLiveServerTestCase
Ok I found the solution. First I had to add in setting
STATIC_ROOT = 'my static dir'
then:
./manage.py collectstatic
I had a similar issue and none of the answers above helped me.
For anyone using Whitenoise as a static file server, it turns out you may have to change the value of the STATICFILES_STORAGE
setting in your app, from:
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
To:
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
That fixed my problem. See this page for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With