About 'main' app, and using it from other apps.

45 views
Skip to first unread message

Marsanghas

unread,
Dec 10, 2017, 10:49:25 AM12/10/17
to django...@googlegroups.com
Hi all!

Started with Django a few days ago (version 2.0, Python 3.6.3). As a noob (no experience with Python and Django, and very little with MVC (sorry, MTV ;-) ), I have a little question that wasn't really clear to me from the tutorial.

When creating a project, for example 'my_first_django' and creating the polls app, my directory structure would be:

    my_first_django
        \_ my_first_django
    \_ polls

Those 2 (\_ my_first_django and \_ polls) are both apps, right? my_first_django being the 'main' app, with the projects' settings.py. I didn't really get that from the tutorial.
My confusion comes from the fact that I want to create a site project and it feels more logical to start with the 'main' app and build modules (apps) next to it. The tutorial doesn't start there.

What is the common practice? Don't use the 'main' app ( my_first_djano in this case ) as an app at all, only just for some global settings, or use it as the main app and create other apps as 'modules' that can be used from within the main? Maybe a silly question. Sorry about that.

I am also asking because I want to use template inheritence in the polls app. I got it working by putting a base.html in /my_first_django/my_first_django/templates , in /my_first_django/my_first_django/apps.py I put:

    from django.apps import AppConfig

    class MainConfig(AppConfig):
        name = 'my_first_django'

And set that in the settings.py [INSTALLED_APPS] section ( 'my_first_django.apps.MainConfig', ). (I probably shouldn't have used MainConfig but MyFirstDjangoConfig, right?)

Now I can call the base.html template from the template in the polls app:

    {% extends "base.html" %}

Is this the correct way to go about it?

Thanx for any help!

Regards,
Marcel

Dylan Reinhold

unread,
Dec 10, 2017, 1:43:06 PM12/10/17
to django...@googlegroups.com
No, I would not think of the my_first_django folder as the main app.
If you have common stuff create a new app named common or base and put your stuff in there.

Dylan


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/H7r0YWfmP5B1qPCxVIbx-5Hwe6x4OfdwV7zrAxjOdgDkFjNMI1DCWfm3EpB23eXP-Y0-pVzlrNSXsuU6rKODJQ%3D%3D%40i-am-b.org.
For more options, visit https://groups.google.com/d/optout.

Marsanghas

unread,
Dec 11, 2017, 1:32:23 PM12/11/17
to django...@googlegroups.com
Thank you. Took your advise and created a seperate app for some common stuff + homepage.





To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages