Hi All,
I'm struggling to work out how best to do what I think I want to do - now it may be I don't have a correct understanding of what's best practice, so if not, feel free to howl at me etc.
Basically, my question is, how do I abstract application functionality correctly, said functionality being found in an application that is part of a project?
To put some context on this (this is not far away from what I'm trying to achieve):
Suppose, I am building a website. My website has a look and feel and I've defined a base.html
piece of boilerplate and various css-items in a model-less django app.
Now, I'm also writing a django blog application. I know how to include it so that the models appear in my current application and I'm more than happy that I can use any method I like from the various packages and manipulate the models and do thing all python with it.
What I don't understand is how to deal with views. It seems counter-intuitive to have the models stored elsewhere but have to build the user interface in my current project (and by implication any subsequent project). So, I thought, fine, include urls
from my app folder in my project, done.
Then of course I have to write views, which is fine. I can do that.
What I can't get my head around is how templates fit in: in my app, I want to serve a template like this:
<div class="entry">
<a href=""><h2>{{ entry.Title }}</h2></a>
<p>Published on: {{ entry.date_published|date:"j F Y" }}</p>
{{ entry.body_html }}
</div>
<a href="">X comments.</a> <a href=""">Add Comment</a> <a href="">Link</a>
<div id="commentdiv">
{% if comments %}
<ul id="commentlist">
{% for comment in Comments %}
<li></li>
{% endfor %}
</ul>
{% else %}
<p>There are no comments on this entry.</p>
{% endif %}
</div>
for viewing an entry, so on my site I go to sitename.com/blog/...someparameters.../entryname' where blog is the
includein
urls.py` of the root project in question. All fine and well, but how do I also attach the boilerplate from that project i.e. the look and feel? I could go all out and design a base template for the blog application, fair enough, but what about navigation etc? I might want to include the same header on every page even if the content is fairly diverse.
Now, I'm aware of the {% extends "template" %} directive and {% include template %} directive. Why these don't work as far as I understand it:
- {% extends %} - how do I know/provide what I want to extend from the root project? If you can provide a mechanism for this I think it would solve the problem very well.
- {% include %} - implies I have to provide views for the blog in a bootstrap application in the root project. I really don't want to do this - I might as well move the entire project into that if that's the case.
So my question is, how do I put it all together?
Edit: I think this question is quite similar to what I'm asking and have noted the answers. However, they're still don't satisfy.