How to do a reusable plugin in Django, that can be included into a template?
up vote
1
down vote
favorite
How to do a reusable plugin in Django, that can simply be included into a template?
I read several tutorials. They all describe views that return a HttpResponse and extend a base template. That is useful for the main view. But how to set up a simple drop-in view, that just sits in the sidebar of other apps?
I name this requirements:
- It must not return a HttpResponse, as this is done by the main view.
- It should be able to display a model.
- It is easy to include.
- It should run out-of-the-box without copying and adjusting the plugin's template first.
Questions:
- How does the interface look like and how is this interface used by the project?
- How is the technology called?
- How is this genre of packages called on PyPi?
- Can you name an example package that shows a canonical implementation?
I guess there are tons of answers, yet it is difficult to find them, as my search keywords are not specific enough. So please excuse to bring up this question, that may sound self-evident to the experienced Django developer.
django django-templates django-views django-apps
add a comment |
up vote
1
down vote
favorite
How to do a reusable plugin in Django, that can simply be included into a template?
I read several tutorials. They all describe views that return a HttpResponse and extend a base template. That is useful for the main view. But how to set up a simple drop-in view, that just sits in the sidebar of other apps?
I name this requirements:
- It must not return a HttpResponse, as this is done by the main view.
- It should be able to display a model.
- It is easy to include.
- It should run out-of-the-box without copying and adjusting the plugin's template first.
Questions:
- How does the interface look like and how is this interface used by the project?
- How is the technology called?
- How is this genre of packages called on PyPi?
- Can you name an example package that shows a canonical implementation?
I guess there are tons of answers, yet it is difficult to find them, as my search keywords are not specific enough. So please excuse to bring up this question, that may sound self-evident to the experienced Django developer.
django django-templates django-views django-apps
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How to do a reusable plugin in Django, that can simply be included into a template?
I read several tutorials. They all describe views that return a HttpResponse and extend a base template. That is useful for the main view. But how to set up a simple drop-in view, that just sits in the sidebar of other apps?
I name this requirements:
- It must not return a HttpResponse, as this is done by the main view.
- It should be able to display a model.
- It is easy to include.
- It should run out-of-the-box without copying and adjusting the plugin's template first.
Questions:
- How does the interface look like and how is this interface used by the project?
- How is the technology called?
- How is this genre of packages called on PyPi?
- Can you name an example package that shows a canonical implementation?
I guess there are tons of answers, yet it is difficult to find them, as my search keywords are not specific enough. So please excuse to bring up this question, that may sound self-evident to the experienced Django developer.
django django-templates django-views django-apps
How to do a reusable plugin in Django, that can simply be included into a template?
I read several tutorials. They all describe views that return a HttpResponse and extend a base template. That is useful for the main view. But how to set up a simple drop-in view, that just sits in the sidebar of other apps?
I name this requirements:
- It must not return a HttpResponse, as this is done by the main view.
- It should be able to display a model.
- It is easy to include.
- It should run out-of-the-box without copying and adjusting the plugin's template first.
Questions:
- How does the interface look like and how is this interface used by the project?
- How is the technology called?
- How is this genre of packages called on PyPi?
- Can you name an example package that shows a canonical implementation?
I guess there are tons of answers, yet it is difficult to find them, as my search keywords are not specific enough. So please excuse to bring up this question, that may sound self-evident to the experienced Django developer.
django django-templates django-views django-apps
django django-templates django-views django-apps
edited Nov 11 at 13:20
asked Nov 11 at 10:41
Blcknx
770119
770119
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
If you don't want to change anything in the base template or in any other view, then best to use a Django Middleware. You manipulate the HTML string that is sent to the browser, adding your "sidebar" HTML/CSS/JS to it.
That way, you can activate your sidebar simply by adding your Middleware to the MIDDLEWARE
list in your project's settings.py
file.
1
That's an interesting approach to inject HTML code. Yet I want to manipulate the base temple, to control where the plugin output goes. I just don't want to manipulate the plugins template by default.
– Blcknx
Nov 11 at 12:00
3
Ah okay, then I misunderstood. If its okay to manipulate the base template, you could insert the plugin as a template tag instead.
– C14L
Nov 11 at 12:05
1
Thank you. This should work. The magic is in the load command. The terminology "tag" is just not that intuitive for a plugin to find it easily. Is there a genre name for this kind of plugins on PyPi? Can you name one, that demonstrates the canonical implementation?
– Blcknx
Nov 11 at 12:51
1
Any app can register template tags. They usually go into a foldertemplatetags
within the app's folder. For example django-allauth provides two tags to display user data in templates.
– C14L
Nov 11 at 13:42
1
To be specific, an inclusion tag is what you need here.
– Daniel Roseman
Nov 11 at 15:15
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
If you don't want to change anything in the base template or in any other view, then best to use a Django Middleware. You manipulate the HTML string that is sent to the browser, adding your "sidebar" HTML/CSS/JS to it.
That way, you can activate your sidebar simply by adding your Middleware to the MIDDLEWARE
list in your project's settings.py
file.
1
That's an interesting approach to inject HTML code. Yet I want to manipulate the base temple, to control where the plugin output goes. I just don't want to manipulate the plugins template by default.
– Blcknx
Nov 11 at 12:00
3
Ah okay, then I misunderstood. If its okay to manipulate the base template, you could insert the plugin as a template tag instead.
– C14L
Nov 11 at 12:05
1
Thank you. This should work. The magic is in the load command. The terminology "tag" is just not that intuitive for a plugin to find it easily. Is there a genre name for this kind of plugins on PyPi? Can you name one, that demonstrates the canonical implementation?
– Blcknx
Nov 11 at 12:51
1
Any app can register template tags. They usually go into a foldertemplatetags
within the app's folder. For example django-allauth provides two tags to display user data in templates.
– C14L
Nov 11 at 13:42
1
To be specific, an inclusion tag is what you need here.
– Daniel Roseman
Nov 11 at 15:15
|
show 1 more comment
up vote
2
down vote
If you don't want to change anything in the base template or in any other view, then best to use a Django Middleware. You manipulate the HTML string that is sent to the browser, adding your "sidebar" HTML/CSS/JS to it.
That way, you can activate your sidebar simply by adding your Middleware to the MIDDLEWARE
list in your project's settings.py
file.
1
That's an interesting approach to inject HTML code. Yet I want to manipulate the base temple, to control where the plugin output goes. I just don't want to manipulate the plugins template by default.
– Blcknx
Nov 11 at 12:00
3
Ah okay, then I misunderstood. If its okay to manipulate the base template, you could insert the plugin as a template tag instead.
– C14L
Nov 11 at 12:05
1
Thank you. This should work. The magic is in the load command. The terminology "tag" is just not that intuitive for a plugin to find it easily. Is there a genre name for this kind of plugins on PyPi? Can you name one, that demonstrates the canonical implementation?
– Blcknx
Nov 11 at 12:51
1
Any app can register template tags. They usually go into a foldertemplatetags
within the app's folder. For example django-allauth provides two tags to display user data in templates.
– C14L
Nov 11 at 13:42
1
To be specific, an inclusion tag is what you need here.
– Daniel Roseman
Nov 11 at 15:15
|
show 1 more comment
up vote
2
down vote
up vote
2
down vote
If you don't want to change anything in the base template or in any other view, then best to use a Django Middleware. You manipulate the HTML string that is sent to the browser, adding your "sidebar" HTML/CSS/JS to it.
That way, you can activate your sidebar simply by adding your Middleware to the MIDDLEWARE
list in your project's settings.py
file.
If you don't want to change anything in the base template or in any other view, then best to use a Django Middleware. You manipulate the HTML string that is sent to the browser, adding your "sidebar" HTML/CSS/JS to it.
That way, you can activate your sidebar simply by adding your Middleware to the MIDDLEWARE
list in your project's settings.py
file.
answered Nov 11 at 11:33
C14L
7,17531736
7,17531736
1
That's an interesting approach to inject HTML code. Yet I want to manipulate the base temple, to control where the plugin output goes. I just don't want to manipulate the plugins template by default.
– Blcknx
Nov 11 at 12:00
3
Ah okay, then I misunderstood. If its okay to manipulate the base template, you could insert the plugin as a template tag instead.
– C14L
Nov 11 at 12:05
1
Thank you. This should work. The magic is in the load command. The terminology "tag" is just not that intuitive for a plugin to find it easily. Is there a genre name for this kind of plugins on PyPi? Can you name one, that demonstrates the canonical implementation?
– Blcknx
Nov 11 at 12:51
1
Any app can register template tags. They usually go into a foldertemplatetags
within the app's folder. For example django-allauth provides two tags to display user data in templates.
– C14L
Nov 11 at 13:42
1
To be specific, an inclusion tag is what you need here.
– Daniel Roseman
Nov 11 at 15:15
|
show 1 more comment
1
That's an interesting approach to inject HTML code. Yet I want to manipulate the base temple, to control where the plugin output goes. I just don't want to manipulate the plugins template by default.
– Blcknx
Nov 11 at 12:00
3
Ah okay, then I misunderstood. If its okay to manipulate the base template, you could insert the plugin as a template tag instead.
– C14L
Nov 11 at 12:05
1
Thank you. This should work. The magic is in the load command. The terminology "tag" is just not that intuitive for a plugin to find it easily. Is there a genre name for this kind of plugins on PyPi? Can you name one, that demonstrates the canonical implementation?
– Blcknx
Nov 11 at 12:51
1
Any app can register template tags. They usually go into a foldertemplatetags
within the app's folder. For example django-allauth provides two tags to display user data in templates.
– C14L
Nov 11 at 13:42
1
To be specific, an inclusion tag is what you need here.
– Daniel Roseman
Nov 11 at 15:15
1
1
That's an interesting approach to inject HTML code. Yet I want to manipulate the base temple, to control where the plugin output goes. I just don't want to manipulate the plugins template by default.
– Blcknx
Nov 11 at 12:00
That's an interesting approach to inject HTML code. Yet I want to manipulate the base temple, to control where the plugin output goes. I just don't want to manipulate the plugins template by default.
– Blcknx
Nov 11 at 12:00
3
3
Ah okay, then I misunderstood. If its okay to manipulate the base template, you could insert the plugin as a template tag instead.
– C14L
Nov 11 at 12:05
Ah okay, then I misunderstood. If its okay to manipulate the base template, you could insert the plugin as a template tag instead.
– C14L
Nov 11 at 12:05
1
1
Thank you. This should work. The magic is in the load command. The terminology "tag" is just not that intuitive for a plugin to find it easily. Is there a genre name for this kind of plugins on PyPi? Can you name one, that demonstrates the canonical implementation?
– Blcknx
Nov 11 at 12:51
Thank you. This should work. The magic is in the load command. The terminology "tag" is just not that intuitive for a plugin to find it easily. Is there a genre name for this kind of plugins on PyPi? Can you name one, that demonstrates the canonical implementation?
– Blcknx
Nov 11 at 12:51
1
1
Any app can register template tags. They usually go into a folder
templatetags
within the app's folder. For example django-allauth provides two tags to display user data in templates.– C14L
Nov 11 at 13:42
Any app can register template tags. They usually go into a folder
templatetags
within the app's folder. For example django-allauth provides two tags to display user data in templates.– C14L
Nov 11 at 13:42
1
1
To be specific, an inclusion tag is what you need here.
– Daniel Roseman
Nov 11 at 15:15
To be specific, an inclusion tag is what you need here.
– Daniel Roseman
Nov 11 at 15:15
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247931%2fhow-to-do-a-reusable-plugin-in-django-that-can-be-included-into-a-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown