I've been playing around with mezzanine for a couple days and I've been following this blog, which has been very helpful.
I'm now at the point where I need to make a bunch of pages that need to be based off of a custom template. My custom template is called content.html
I've put it in myProject > myApp/theme folder > templates > pages > content.html but when I look in the admin console, I don't see content in the drop down menu.
How do I get mezzanine to recognize my content.html page as a template?
content.html will not automatically appear in your site's drop down menu.
You need to go to the admin site and explicitly declare a page my content where you would like content.html to appear in your page hierarchy.
For mezzanine to match the two (i.e. template content.html and admin page my content):
Either my content's Title field (in admin site) should be content,
Or, URL field (in the meta data section of my content) should be content (if you decide the title will not be content),
Or, if you want content.html to have a custom slug, say nicecontent, then fill URL field with nicecontent and add to url.py a pattern for content.html with a matching slug, so:
url("^nicecontent/$", direct_to_template, {"template": "path/to/content.html"}, name="name_for_content").
There's a method Mezzanine uses for looking up template names, from the broadest ("page.html", which all other templates also extend), to templates named for their content types (richtextpage.html, gallery.html, etc), down to the most granular level, which is templates matching the url/slug of individual pages.
This is all covered in the documentation:
http://mezzanine.jupo.org/docs/content-architecture.html#page-templates
It sounds like you might be looking for "page.html", but it's not clear from your question.
Related
I want to add a common sidebar for all my templates on my site. Let's say, I want a picture and some text, that the final user could modify whenever she feels like without having to mess with my base.html template (the base class of all my templates).
To be clear, I know that I can put plugin place holders with the template tag:
{% placeholder sidebar %}
My problem is that if I have five 5 templates and the content of the sidebar is the same for all of them, the user have to go through all the pages and change them one by one.
On the other hand, it cannot be static because I want the user to be able to modify the content through the admin.
Specifically, I am trying to do this with the cmsplugin-contact which saves me the troubles of configuring forms and emails.
You can create a special page that isn't published and add a "sidebar" placeholder to the template. You then use the {% show_placeholder %} template tag to render that sidebar placeholder in the base template that each of your 5 other pages are using
My problem
With Django CMS 2.3.3, when creating a Page I use cmsplugin_picture* next to a couple of other cmsplugins. In my cms template, instead of doing:
{% placholder "content" %} //calling the Django Page including all plugins...
I would like to call each cmsplugin seperately, but how would I do that?
I looked at Django tag template (filters) here and also studied Django CMS template tags here, but neither seem to suggest that possibility. I have to say I am a beginner so I might not have connected the dots...
What I try to achieve:
In my template I have a IMG tag (outside of the {% placeholder "content" %} tag) which I want to populate with an image url that I define in my Page/cmsplugin_picture. So I am looking for a placeholder tag that allows me to grab that image. In my wildest dreams I would name it:
{% show_placeholder "content" request.current_page.get_cmsplugin_picture %}
Obviously the above doesn't work, but does something like this exist?
**I have also tried cmsplugin_filer, but to me it isn't necessarely more beneficial to fix this particular problem.*
EDIT:
What I mean by Page/cmsplugin_picture -> In a Django CMS Page you can select between your installed cmsplugins to add to a Page. In my case I select cmsplugin_picture and upload an image (within that plugin). This image I want to 'call' in my Django Template. So it is a not a static url, but dynamic.
You should make a second placeholder where your img tag is (and optionally limit the types and amount of plugins using CMS_PLACEHOLDER_CONF (http://docs.django-cms.org/en/2.3.3/getting_started/configuration.html#cms-placeholder-conf).
At present, Django admin will show all the mandatory fields with a bold labels. Is it possible mark with * in the label instead of bold labels?
The Django admin uses templates to render the add/edit page for a model. It is possible to replace that template with one of your own (which extends from the original template) overriding the template blocks you need to in order to make the changes you want to.
Check out the Django docs regarding overriding admin templates for more information.
It's the admin/change_form.html template which you would need to alter in some way (since this template renders the page shown when you add a new instance or edit an existing one). The existing templates already apply a required class to the appropriate labels, so I would create a new template which looks like this:
{% extends "admin/change_form.html" %}
{% block extrastyle %}
{{ block.super }}
<style type="text/css">
/* add an asterisk using CSS */
.required:after {
content: " *";
}
</style>
{% endblock %}
Apply to a Single Model
You should use a model admin class if you want this template to be used for specific models, setting the change_form_template attribute, as described in this section of the docs to the location of the template file you have created.
Apply to a Single App
If you want template to apply to models in an entire app create a templates folder inside the root of the app. Django will automatically look for templates there, so if you create a folder called admin and place a file in there called change_form.html it will automatically override the default Django template of that name (admin/change_form.html).
Project Wide
In order to apply this template project wide create a folder somewhere (not inside an app) called templates. Again place your new template in this directory at admin/change_form.html.
Next edit the template directories Django setting specifying the location of this directory in order to allow Django to find the template and override the default templates in the same way as before only project wide and not just app wide.
This is quite a complex set of things to do, especially for such a simple change and you may find it tricky if you have not worked with admin templates before (or even if you have).
Hopefully you now understand what is required to change an admin template, its actually fairly elagant (as is Django) but in my opinion not worth the effort just to change to some asterisks.
How can I include with Django what Symfony calls 'components' - bits of logic and a template that's not associated with the content of the current page?
For example I want to include a sidebar that displays a list of the top 10 articles on the site. It should always be displayed if the user is looking at either an 'article' page or a 'video' page. Also, the top 10 articles component needs its own CSS and JS as well as producing content.
If I have a base template that contains sections for "content", "css" and "js", and 'article' and 'video' templates that extend the base template and then define "sidebar" blocks inside "content", what's the 'Django' way of going about this?
Thanks
Custom tags are what you want - specifically, inclusion tags that let you render another template within the current one.
I'm building a Blog in Django (using Generic Views) and I use the same template for both my date based and list detail views. I'm trying to setup pagination, but I want to do so with URL patterns rather than using an ugly ?page=1 url suffix.
The problem is in the actual html template, I cannot find a way to determine which view was used to render the page, so while I have access to all the pagination stuff, I have no way to generate the appropriate URL.
In other words, if the view was rendered by my archive_month(request, month, year, page=0) view, I would need to structure the URL for the next and previous pages as /blog/dec/2009/PageX/, versus the blog index, which would mean the URL would be /blog/pageX/.
Well I just realized that date_based generic views don't support pagination, so problem solved.