0

So I have 2 apps for my django project. In the default mysite folder, you have the urls.py file. I cant seem to find out how to write all my urls for all the apps in just the one urls.py file.

I have tried this:

from reviews.models import *

however that isnt working.

Thanks for any help!

wtreston
  • 1,051
  • 12
  • 28

2 Answers2

0

Just realised that i was importing the models instead of the views.

the code above should be from reviews.views import *

wtreston
  • 1,051
  • 12
  • 28
  • I would import the views themselves by name, rather than using `*`. Your current version is a major code smell and violates best practices – Jason Dec 28 '17 at 14:19
  • Right ok. Should I do the same when I import my models into my views? Also why is it considered a major code smell? – wtreston Dec 28 '17 at 14:21
  • correct, I would make it a habit to import by specific name, and avoid `*` unless you're absolutely certain that you need everything in the module being imported. For more reading, check out https://stackoverflow.com/questions/2386714/why-is-import-bad – Jason Dec 28 '17 at 14:23
0

Try and prevent confusion with explicit view names, explicit is better than implicit

from reviews import views as reviews_views
from other_app import views as other_app_views
tread
  • 10,133
  • 17
  • 95
  • 170