pydanny / cookiecutter-djangopackage

A cookiecutter template for creating reusable Django packages quickly.
436 stars 153 forks source link

Inaccurate test instructions #968

Closed luizanao closed 3 years ago

luizanao commented 3 years ago

Description

Only following these instructions I couldn't get the app up and running. (Plus whoever will fix it, can take advantage of the PR and fix the README h1)

To get it running you need either run it passing PYTHONPATH=tests/ (which in this case could be added to the README.md ) or preppend tests. to the wsgi app

What I Did

$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 27, 2020 - 17:48:07
Django version 3.1.2, using settings 'tests.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'example'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/luiz/.pyenv/versions/3.6.9/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Users/luiz/.pyenv/versions/3.6.9/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 138, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 65, in get_handler
    return get_internal_wsgi_application()
  File "/Users/luiz/.pyenv/versions/myapp/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 50, in get_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'example.wsgi.application' could not be loaded; Error importing module.

I can take care of it if you agree this is indeed not desired. Also, any preferences on the fixes? I'd say patching the wsgi.py would make more sense to me

jonathan-s commented 3 years ago

Thanks for reporting this. You are indeed correct. If the following code snipped would be added to tests/wsgi.py and then the settings modified accordingly. You'd be able to run the app.

"""
WSGI config for foxflash project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
application = get_wsgi_application()
luizanao commented 3 years ago

Thanks for checking it out (and for the solution for free 😄 ) @jonathan-s . I can take time today evening to patch it if you haven't done yet

jonathan-s commented 3 years ago

Please do send a patch, then you can confirm that it's actually working :)

luizanao commented 3 years ago

@jonathan-s #969 is good for reviewing now :)

It will be appreciated if you label the PR as hacktoberfest-accepted since I found this creating another open-souce for hacktoberfest :) Lemme know if you need any clarifications

jonathan-s commented 3 years ago

Closed by #969