drf-forms / drf-schema-adapter

Making using Django with frontend libraries and frameworks DRYer
http://drf-schema-adapter.readthedocs.io/en/latest/
MIT License
157 stars 40 forks source link

ROOT_URLCONF #58

Open jayvdb opened 4 years ago

jayvdb commented 4 years ago

The default urls should be django.conf.settings.ROOT_URLCONF, not 'urls'.

  File "/usr/lib/python3.8/site-packages/export_app/base.py", line 22, in __init__
    self.router = import_string(settings.ROUTER_PATH)
  File "/usr/lib/python3.8/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'urls'
jayvdb commented 4 years ago

Note that just setting EXPORTER_ROUTER_PATH = ROOT_URLCONF didnt do the trick. Note I use the DJango layout where there is a project subdirectory with settings.py/urls.py/wsgi.py/etc.

ROOT_URLCONF = '<project_name>.urls'
EXPORTER_ROUTER_PATH = ROOT_URLCONF
  File "/usr/lib/python3.8/site-packages/export_app/base.py", line 22, in __init__
    self.router = import_string(settings.ROUTER_PATH)
  File "/usr/lib/python3.8/site-packages/django/utils/module_loading.py", line 22, in import_string
    raise ImportError('Module "%s" does not define a "%s" attribute/class' % (
ImportError: Module "<project_name>" does not define a "urls" attribute/class
devo-wm commented 4 years ago

Running into the same issues over here as well! Love the concept and all the progress made so far!

nanuxbe commented 4 years ago

it is neilther django.conf.settings.ROOT_URLCONF, nor 'urls', 'urls' is just the default. The correct value which should indeed be set in settings as EXPORTER_ROUTER_PATH is the module in which you have imported and configured your router, ie:

from drf_auto_endpoint.router import router

router.registerViewSet(....)
router.register(...)

urlpatterns = [
    ...
    url(r'api/vx/', include(router.urls)),
]

Depending on what structure you decided for your project, this might be in 'urls', django.conf.settings.ROOT_URLCONF, 'any_of_may_apps.api_urls'

Do you have any suggestions on how to make this more clear in the documentation?

jayvdb commented 4 years ago

This issue is not about documentation; it should be obvious from my text above I know how to change that setting.

This issue is about improving the default. Don't you think that django.conf.settings.ROOT_URLCONF is a good default? Why is urls a better default?

nanuxbe commented 4 years ago

@jayvdb I'm not saying you don't know how to change the settings, my answer was not directed specifically at you but was trying to answer both people involved in this thread.

I don't think django.conf.settings.ROOT_URLCONF because I have run into a lot of people who are (and tutorials that advocate) setting their api urls in a separate file. The idea behind a default that "doesn't work" is that people do have to set it to accommodate their own particular setup.

jayvdb commented 4 years ago

Then it should not have a value at all, and the settings layer of drf-schema-adapter can detect that and raise ImproperlyConfigured with a helpful message.