how to make interaction between different django apps in a single site?
Asked Answered
C

1

7

I have just learnt about Django apps. I want to know that within one site, if I make different apps. like, users, profiles, polls, blogs,comments, jobs , applications then how can I manage them to make them intereactive? And is it how the concept of app should be? I want to have things loosely coupled that's why asking? Rails work on the way of REST, so do Django support that also with the use of apps? May be my questions seems a bit ambiguous because I am new to django and some of my concepts are still messed up.

Please tell what ever you know.

Cowage answered 3/11, 2011 at 20:28 Comment(0)
F
5

The general idea is that apps should be as loosely coupled as possible. The goal is to have completely self-contained functionality. Now, of course, that's not always possible and many times it even makes sense to bring in functionality from another app. To do that, you simply import whatever you need. For example, if your "blogs" app needed to work with your Comment model in your "comments" app you'd simply add the following to the top of the python file you're working in:

from comments.models import Comment

You can then use Comment as if it were defined right in the same file.

As far as REST goes, Django's views are much more fluid. You can name your view whatever you like; you need only hook it up to the right urlpattern in urls.py. Django views can return any content type, you just prepare the response and tell it what mimetype to serve it as (the default is HTML).

Fuzee answered 3/11, 2011 at 20:52 Comment(2)
so my idea about app is almost correct in the way that I can have, comments and blog as two different apps. And I want to ask that can I also use other app's view or template part as well?Like if I have one app as Jobs and other as applicaions so I want to show applications under jobs. Then I may be need some time template of applications as well.Cowage
You can pretty much do whatever you like. An "app" is merely a self-contained unit of logic. You can use its models, views, templates, static resources, whatever, in any other app. For things like models and views, you simply import them as explained above. For things like templates and static resources, you merely reference their path in another template for something like {% extend %} or a <script> or <link> tag.Fuzee

© 2022 - 2024 — McMap. All rights reserved.