I have created html template named testTemplate which is added to CMS_TEMPLATES:
CMS_TEMPLATES = (
## Customize this
('fullwidth.html', 'Fullwidth'),
('sidebar_left.html', 'Sidebar Left'),
('sidebar_right.html', 'Sidebar Right'),
('testTemplate.html', 'testTemplate')
)
Then in fullwidth.html file I have changed the {% extends "base.html" %} to {% extends "testTemplate.html" %}. In testTemplate.html file I can find few {% placehoders %}. And now if I want to go to django-cms to add a content to placeholders, my cms-admin does not look right. Layout of cms admin looks like the template elements. How to separate the cms-admin template and my site template to make it work correctly?
I'm not sure I completely understand your issue. Are you wanting to use testTemplate.html instead of base.html or are you wanting to insert testTemplate.html between base.html and fullwidth.html?
If you want to replace base.html, then I would simply save testTemplate.html in the same location as base.html and not bother registering it with CMS_TEMPLATES. Registering with CMS_TEMPLATES simply makes these templates available to your pages in cms-admin. If testTemplate.html is not a final template that you will want to use then you don't need to register it here. Note that base.html is not registered here for that very reason. Another approach would be to rename base.html as something else and renaming testTemplate.html to base.html, effectively replacing it if you don't want to use the original, which means you wouldn't need to change any of the dependant templates.
If you are trying to insert testTemplate.html between base.html and fullwidth.html, that is a different kettle of fish. You will need to make sure you have all your blocks nested correctly and you'll need to post some more details like your html code for each page for people to be able to assist you.
Related
I have base.html (which is my home page). It has navbar which is in navbar.html and some sliders in base.html itself. I have created ProductList view which render context(i.e products), which is used in product_list.html to make values dynamic.
Now my problem is I don't want to include my ProductList view in my product.urls because i don't want it to be rendered in new page. Instead I want to include product_list.html in base.html inorder to show it in my home page rather than in product page just like in normal ecommerce site.
So, I didn't include ProductList in product.urls and included that template in base.html using include template-tag. But it didn't show my products. When i tried to render products in separate page it works.
Is there any method to do this?
I think you forget to pass the context.In your views.py, pass the context to the function which renders the base.html
For example:
def index(request):
context = {'product':products} #Pass your products
return render(request,'base.html',context)
I have designed and coded a website (with bootstrap 4) and now I would like to import it in Django CMS so the client can edit the content.
Any tips or guide that helps me to achieve this?
Thanks a lot
You have to make it into a template and import the information itself separately. Add new template to settings.py.
If your client already has a basic template that you're editing you may simply edit his existing files and CSS. Alternatively, you may also download/import an existing template and use it as your base for editing.
The template itself will look something like this: default template: base.html,
{% load i18n %}
{% extends 'base.html' %}
{% block title %}Title Here{% endblock %}
{% block content %}
{% endblock %}
#A-creative At first you should copy Bootstrap 4 static files (css and js) into your "projectname/appname/static" dir, run "python manage.py collectstatic" and then just copy your Bootstrap-ready html into the cms using Style, Text and Snippet plugin fields (Admin > Create new page > Edit > Add plugin/block > ...). You should do it page by page.
I doubt there is a shorter way... Yeap, and your should use a standard minimalistic template as mentioned by #Patriot to avoid dealing with template issues and plugin / html issues at the same time.
Currently, I use the following code to include another HTML file:
{% include "machines/opennebula/resources.html" %}
I am adding another folder to add another version of resources.html (specifically to support OpenStack when I want to swap to using that cloud platform):
machines/openstack/resources.html
I want to have the path change based on whichever is set in a config file (which I incorporate into other parts of the file I'm working on using):
{{ cloudPlatform }}
I tried:
{% include "machines/{{ cloudPlatform }}/resources.html" %}
This worked when using it in association with the script tag however it hasn't worked with Django's include statement. My question is how do I make something equivalent (that works in HTML) with Django?
currently I'm working on static website, so I'm using jekyll to generate it. To have a nice structure and fancy URLs, I use permalinks.
permalink: /impressum/
So for example the impressum.html is rendered to impressum/index.html. And in my HTML i can simply link to that file with
<a href="/impressum">
That works for me very well. But you know, I'm a programmer. What if I want for example to change the URL to /imprint/? Well, I can change the permalink without any problems. But what's about all the other links on the site? Yeah, sure, I can use the search & replace function of my editor to change the linked URLs and check the whole site with a site checker for broken links, but that's not the fancy way I want to go. That's why I tried to create some kind of global variables with the permalink.
_config.yml:
lnk_impressum: /impressum/
impressum.html
---
layout: layout
title: Your New Jekyll Site
permalink: {{ site.lnk_impressum }}
---
But that does not work. I get this error:
Generating... error: no implicit conversion of Hash into String. Use --trace to view backtrace
So what's wrong or is there a better way?
It doesn't seem to be possible to place Liquid tags inside the YAML Frontmatter or _config files, per this SO answer.
Something else you could try is based on the approach used by the documentation pages for Bootstrap, which uses a Page Variable they call slug that provides a unique, unchanging reference to each page.
For instance, if you'd like to place a link to your impressum.html page (for which the permalink could change), you can place this code on another page, such as index.html:
{% for mypage in site.pages %}
{% if mypage.slug == 'impressum' %}
Link to Impressum page
{% endif %}
{% endfor %}
Then, in the YAML frontmatter for each of your pages, place code similar to the following:
---
slug: impressum
permalink: /my-permalink-to-impressum/
---
To change your permalinks in the future, you would just make the change to the Page Variable permalink in each page. The URLs referenced in your other pages would be automatically updated by Jekyll, as long as the slug variable remains unchanged.
I've been looking around everywhere and trying everything but i cannot seem te get my css file to work in a Django template.
My css i called style.css
the code in the template right now looks like:
{% load staticfiles %}
<link rel="stylesheet" href="{{ STATIC_URL }}style.css" type="text/css" media="screen" />
I'm still working on the development server.
In settings py I added:
STATICFILES_DIRS = (
"home/henk-jan/website/Template/Database")
django.contrib.staticfiles is installed in Installed_apps
can anyone help me with this?
Cheers, Henkes
Edit: My template (index.html) is in the same folder as my style.css the folder is: /home/henk-jan/website/Template/Database
From looking at your original post it would appear to me that your working at rendering your page from two separate angles.
First, you have {% load staticfiles %} which will load the templatetags associated with the staticfiles module. Second, inside your link element you are referencing {{ STATIC_URL }} which gets expanded via context.
From this I would recommend one of the following two courses of action.
1 - Utilize the staticfiles module and the templatetags you loaded in your template.
To do this you should modify your link element to read like this:
<link rel="stylesheet" href="{% static "style.css" %}" type="text/css" media="screen" />
Note that in this instance I have replaced the {{ STATIC_URL }} with the {% static %} templatetag. The {% static %} templatetag takes an argument which is the file you wish to prefix with the static URL, and expands into the complete string.
2 - Make use of context by modifying your view to render with context.
The {{ STATIC_URL }} variable is made available via request context. There are a number of useful variables that are, that you can rely on to get expanded if you want to utilize them. The trouble is that you have to ensure that you render your template with context which means you would potentially have to change one or more views.
As an example an overly simple view that renders without context would look like:
from django.shortcuts import render_to_response
def index_without_context(request):
return render_to_response("index.html")
While the same overly simple view rendered with context would look like this:
from django.shortcuts import render_to_response
from django.templates import RequestContext
def index_with_context(request):
return render_to_response("index.html",
context_instance=RequestContext(request))
As I stated above, by rendering your template with a RequestContext you get other variables and such that can be of use so it is a very viable option.
In the end it really depends on where you want to keep the logic that ensures your static files get your static URL rendered correctly at. If you want that logic inside the template itself I would recommend you go with the {% load staticfiles %} approach and use the {% static %} template tag. If you prefer to make use of the {{ STATIC_URL }} variable as well as having other potentially useful variables available then I would recommend modifying your view to be rendered with a RequestContext.
You can read more about the difference between using the context processor or a template tag in the Django docs section about this very topic:
https://docs.djangoproject.com/en/1.4/howto/static-files/#referring-to-static-files-in-templates
Is "home/henk-jan/website/Template/Database" a valid location? Maybe "/home/henk-jan/website/Template/Database" instead? Right now the preceding forward slash is missing.
If you are working on the development server, you will want to let Django serve the static content. When you go to production you will have your web server handle serving static content instead.
You will want STATIC_URL pointing to the path to your static content (in this case it looks like that would be /Template/Database/. It sounds like you have that working. Now you just need to tell Django to serve static content when in DEBUG mode. See this post: Django MEDIA_URL and MEDIA_ROOT