Hyphens in Django app/project names?

4,315 views
Skip to first unread message

Victor Hooi

unread,
Jan 14, 2011, 9:48:21 PM1/14/11
to django...@googlegroups.com
heya,

I'm just wondering whether you are allowed to use hyphens in Django app/project names?

When I try to create either an app or a project with hyphens in the name, I get an error:
Error: 'django-library' is not a valid app name. Please use only numbers, letters and underscores.
However, I know of several other apps which seem to have hyphens in their name.


In fact, if you look at Django Pluggables (did they get renamed to Django Packages?), every mult-word app seems to use hyphens:


Did they just create the Django directory structure by hand, instead of using manage.py? Is it considered bad practice to use hyphens in names? Are they any good standards documents on Django app/project naming conventions? (I could only find an outdated one at http://homepage.mac.com/s_lott/iblog/architecture/C1597055042/E20070622152523/index.html).

Cheers,
Victor

Russell Keith-Magee

unread,
Jan 14, 2011, 11:27:36 PM1/14/11
to django...@googlegroups.com
On Sat, Jan 15, 2011 at 10:48 AM, Victor Hooi <victo...@gmail.com> wrote:
> heya,
> I'm just wondering whether you are allowed to use hyphens in Django
> app/project names?
> When I try to create either an app or a project with hyphens in the name, I
> get an error:
>
> Error: 'django-library' is not a valid app name. Please use only numbers,
> letters and underscores.
>
> However, I know of several other apps which seem to have hyphens in their
> name.
> https://bitbucket.org/ubernostrum/django-registration
> https://github.com/django-extensions/django-extensions
> https://github.com/jezdez/django-staticfiles

You need to differentiate between the name of the *project* and the
name of the *module*.

Taking django-regsitration as an example -- the *project* is named
'django-registration'. When you install that project into your
PYTHONPATH, it is installed as the *module* named 'registration'.

A hyphen isn't legal when used in a package name -- hence the
restriction in startapp. startapp creates a module that needs to be
imported, so it needs to restrict to legal Python module names.
However, when you distribute your app as a packaged Python module, you
can wrap it in whatever package name you want -- and in this context,
hyphens are legal.

The "django-" prefix is fairly common, allowing you to differentiate
'django-registration' from other web framework registration modules.
However, it isn't a mandated standard or anything like that.

> In fact, if you look at Django Pluggables (did they get renamed to Django
> Packages?),

Django Packages and Django Pluggables are different projects. I'm not
sure what happened to Django Pluggables.

Yours,
Russ Magee %-)

Victor Hooi

unread,
Jan 17, 2011, 7:42:55 PM1/17/11
to django...@googlegroups.com
Russ,

Aha, excellent, thanks for clearing that up =).

I can see you point - django-registration has a module called "registration", django-extensions has a module called "django_extensions", and django-staticfiles has one called "staticfiles". So it seems like I either go for a single-word module name, or replace hyphens with underscores.

Is there any recommendation from the Django team? Is sing underscores as faux-hyphens considered bad practice?

Cheers,
Victor

Russell Keith-Magee

unread,
Jan 23, 2011, 6:42:40 AM1/23/11
to django...@googlegroups.com

The only recommendation I would make is that the name you choose is
essentially the interface to your api, so make it easy to use.

django_foobar is accurate, but a PITA if you have to type it every
time you import/use the app, especially if foobar isn't likely to be
inaccurate in the circumstances.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages