Using django 1.4 and have seen that when you use startproject
it now creates a folder within your project with the same name.
-myproject/ manage.py myproject/ settings.py urls.py
Documented change here
Previously for my urls I could input
ROOT_URLCONF = 'urls'
But that no longer works. Am I now supposed to prefix this with project name? i.e.
ROOT_URLCONF = 'myproject.urls'
-- In my urls.py
I'd import settings but now I have to prefix it with from myproject import settings
.
I thought prefixing variables with the project name was against django standards as it breaks reuseability?
I would just add that it forces you to use prefixes when you accces your main myproject.urls
, but it doesn't force you either way for your apps. You can choose to store apps either in the top-level folder:
myproject |-- manage.py |-- myproject | |-- __init__.py | |-- settings.py | |-- urls.py | `-- wsgi.py `-- polls |-- __init__.py |-- models.py |-- tests.py `-- views.py
This is the default when you use python manage.py startapp polls
In this case you'd use from polls.models import Whatever
Alternatively, you can:
mkdir myproject/polls python manage.py startapp polls myproject/polls
And you'll get this:
myproject |-- manage.py `-- myproject |-- __init__.py |-- polls | |-- __init__.py | |-- models.py | |-- tests.py | `-- views.py |-- settings.py |-- urls.py `-- wsgi.py
In which case you'll have to from myproject.polls.models import Whatever
...
So the former is better for apps you think you might be able to re-use in other projects, and the latter is better for apps that are tightly coupled with other parts of your project.
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