here are my personal thoughts on the proposals:
On Tue, Oct 18, 2011 at 5:21 PM, Rich Jones <mise...@gmail.com> wrote:
> django-admin.py startproject newproj
>
> should create ./static, ./uploads and ./newproj and ./newproj/
> templates
-0
./static might be common, the others are way too specific.
> in ./newproj/settings.py..
>
> import os
> TEMPLATE_DIRS = (
> os.path.join(os.path.dirname(__file__), 'templates'),
> )
+0
i use something similar. i don't like exactly this version, but
getting away from static absolute paths is always good
> and at the end, the commonly used from local settings import * block.
-1
there are too many flavors of that.
> I'd also suggest that django-admin.py startproject newapp, if
> possible, add the new application to the settings.py file if it can be
> done so safely.
-1
once the default settings.py is generated, it's my own; i don't want
any 'help process' meddling with it.
> I would also suggest that when making a new application, the most
> commonly used imports are already there in the py files
> (render_to_response, HttpResonse, get_object_or_404, etc).
0
i like the error messages when i don't include things.
--
Javier
Hi Rich,
On 10/18/2011 04:21 PM, Rich Jones wrote:
> So I've just written a blog post about getting started with Django,
> http://gun.io/blog/python-for-the-web/, and many of the things here
> just make me think, 'why doesn't it just do that by default?'
>
> Here's some of what I propose. I'm not suggesting this be a canonical
> list of features by any means, I'm just suggesting that django have
> more convenient default settings. We should look at the most common
> conventions and best practices and shape the defaults towards them.
Thanks for giving some thought to what would make Django easier for new
users.
> Anyway, I propose that:
>
> django-admin.py startproject newproj
>
> should create ./static, ./uploads and ./newproj and ./newproj/
> templates
+0.5 to creating static/ and templates/ directories. I know people may
use layouts where those live elsewhere, but I don't think I've ever seen
a real production Django codebase that didn't have a directory for
static assets and a main project-wide directory for templates, in the
same repo with the code.
- -1 to creating an uploads/ directory, I've seen (and written) many
projects that never handle user uploads at all.
> in ./newproj/settings.py..
>
> import os
> TEMPLATE_DIRS = (
> os.path.join(os.path.dirname(__file__), 'templates'),
> )
If startproject creates a templates/ dir, +1 to having it in the default
TEMPLATE_DIRS in a portable way like this.
Same with static/ and STATICFILES_DIRS.
> and at the end, the commonly used from local settings import * block.
- -1; this is often done, but it's far from a consensus best practice.
> I'd also suggest that django-admin.py startproject newapp, if
> possible, add the new application to the settings.py file if it can be
> done so safely.
I'd be -1 on this as well for the same reason as Javier.
> I would also suggest that when making a new application, the most
> commonly used imports are already there in the py files
> (render_to_response, HttpResonse, get_object_or_404, etc).
- -1 on this; I frequently have a views.py that doesn't use one or more of
these utilities (what if I prefer TemplateResponse instead of
render_to_response?). Users should get used to the idea that you import
what you actually need to use and don't have unused imports hanging around.
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk6eExEACgkQ8W4rlRKtE2cJAgCfdVEI4pysyolpayYs/oGvam20
WvIAnA34ivGF47ZczmCe/KAkHcqhhXAf
=lpHn
-----END PGP SIGNATURE-----
Hey guys!
So I've just written a blog post about getting started with Django,
http://gun.io/blog/python-for-the-web/, and many of the things here
just make me think, 'why doesn't it just do that by default?'
Here's some of what I propose. I'm not suggesting this be a canonical
list of features by any means, I'm just suggesting that django have
more convenient default settings. We should look at the most common
conventions and best practices and shape the defaults towards them.
Anyway, I propose that:
django-admin.py startproject newproj
should create ./static, ./uploads and ./newproj and ./newproj/
templates
in ./newproj/settings.py..
import os
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
and at the end, the commonly used from local settings import * block.
I'd also suggest that django-admin.py startproject newapp, if
possible, add the new application to the settings.py file if it can be
done so safely.
I would also suggest that when making a new application, the most
commonly used imports are already there in the py files
(render_to_response, HttpResonse, get_object_or_404, etc).
Who's with me? :)
R
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Hello,
Collecting static files and putting media uploads in the "project directory" (whatever that means) isn't really a best practice. In production, the code area should be read-only for the web server user: code goes in /usr/... and data in /var/www/...
In order to make deployment easier, I also recommend putting site-wide templates and templatetags in an application, and keeping TEMPLATE_DIRS empty, but that's a personal preference.
There are many ways to specialize settings by environment, and local_settings.py is only convenient for the smallest projects — as soon as two people work on the project, it's better to have "dev.py" / "prod.py" and to symlink or import * from the appropriate module.
Sorry for sounding negative, but I'm also against import pollution.
In short, I think that Django is a general purpose framework, and putting default values geared towards one-man projects isn't good for us in the long term. I prefer if newcomers have to read the appropriate page of the doc — discovering in the process that we have an excellent documentation — rather than blindly use the template loader or the static files without understanding it, and then complain that it breaks when they deploy to production.
Following Carl's cleanup of the PYTHONPATH mess, we considered writing a documentation page about project layout. It would touch many of the points discussed in your proposal. I think that's the best solution to the question discussed here: "how should I organize my (first) Django project?"
Best regards,
--
Aymeric Augustin.
should create ./static, ./uploads and ./newproj and ./newproj/
templates
and at the end, the commonly used from local settings import * block.
Thanks for the suggestions, Rich... I'll try not to repeat what others have said, but have a couple notes to add:
(....)
As for the rest: I don't believe in adding magic in order to save a couple lines of typing (explicit > implicit), but I am in favor of things we can do to encourage best practices where the community agrees. So to that task I wish you excellent luck!All the best,- Gabriel
Hi Aymeric,
On 10/19/2011 01:07 AM, Aymeric Augustin wrote:
> Collecting static files and putting media uploads in the "project
> directory" (whatever that means) isn't really a best practice. In
> production, the code area should be read-only for the web server
> user: code goes in /usr/... and data in /var/www/...
(FWIW, my +0.5 was for creating a static/ directory that would go in
STATICFILES_DIRS, definitely not setting a default value for STATIC_ROOT).
> In order to make deployment easier, I also recommend putting
> site-wide templates and templatetags in an application, and keeping
> TEMPLATE_DIRS empty, but that's a personal preference.
Just out of curiosity, why would you say it makes deployment easier to
put static assets and templates into an installed app, rather than using
TEMPLATE_DIRS/STATICFILES_DIRS? (Templatetags are a different issue;
those have to go in an app).
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk6ggvQACgkQ8W4rlRKtE2fHVACg2RxqopGeAYaMReVbV/u7SkVq
TuAAn1Zso3AYjGrtem6QFuhpZlq1tJS0
=OpHw
-----END PGP SIGNATURE-----
On 10/19/2011 01:07 PM, Gabriel Hurley wrote:
> I think there is sufficient interest in the idea of a "how to organize
> your Django project" page in the documentation that it would be worth
> beginning work on a patch for one, much in the way that the "How to
> contribute to Django"/"Spirit of contributing" page got started.
Agreed.
> That means:
>
> 1. Opening a ticket for it if one doesn't already exist.
The ticket already exists: https://code.djangoproject.com/ticket/17044
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk6giaUACgkQ8W4rlRKtE2e10ACg55foQJffrStkk3iiekzaxmH6
f9YAoLQrpRPO+H2I8qPfMqssk5shkvrN
=bevB
-----END PGP SIGNATURE-----
>> In order to make deployment easier, I also recommend putting
>> site-wide templates and templatetags in an application, and keeping
>> TEMPLATE_DIRS empty, but that's a personal preference.
>
> Just out of curiosity, why would you say it makes deployment easier to
> put static assets and templates into an installed app, rather than using
> TEMPLATE_DIRS/STATICFILES_DIRS? (Templatetags are a different issue;
> those have to go in an app).
I see two advantages:
- everything is an app: there are no special directories to handle when you build a package,
- templates and static files work with the same settings in development and production.
These arguments aren't very strong:
- you still have to ensure that static files and templates are properly packaged within apps,
- generally, you have different settings in development and production anyway, and the overhead of changing TEMPLATE_DIRS/STATICFILES_DIRS is negligible.
That's why I said it's a personal preference, maybe even an aesthetic matter :)
Hi Rich,
On 10/21/2011 10:21 AM, Rich Jones wrote:
> How would you guys feel about a manage.py startexample
>
> which would create an example application? A simple, templated hello
> world with an example model and an example view and an example
> template?
Indifferent? I kinda feel like following the tutorial gives you this
already, and I'm not real excited about having another "sample project"
in core to maintain and update. OTOH I understand that a lot of people
learn best by tweaking existing working code, and if this were done
outside of core the people who most need it (beginners) are not likely
to be aware of it. Maybe there'd be a way to make it a downloadable part
of the docs rather than a management command?
I'm not going to work on this or commit it, but if other people
(including at least one core dev) are excited about it I wouldn't stand
in the way. So I guess that's a -0.
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk6huGUACgkQ8W4rlRKtE2dAWQCg6mKdlRHDkk+sPYJvafjyms5C
Q2wAoN70oNfxh3vTzd4W7DqrUCzO/RD8
=mCZ7
-----END PGP SIGNATURE-----