How to change Jupyter notebook html output template? - python

I use jupytherthemes module to change Jupyter notebook theme to solarized. For some reason, I needed to reinstall the Anaconda. After that I was not able to use jupytherthemse and I just used another custom.css file and left it in .jupyter/custom directory.
My notebook theme is fine but when I export it as html, nbconver uses the old theme--solarized. I searched a lot to find a way to reset the template to the default template or to custom.css I am using for notebook. I was not able to find any solution.
any thought would be much appreciated.
here is full.tpl content:
{%- extends 'basic.tpl' -%}
{% from 'mathjax.tpl' import mathjax %}
{%- block header -%}
<!DOCTYPE html>
<html>
<head>
{%- block html_head -%}
<meta charset="utf-8" />
<title>{{resources['metadata']['name']}}</title>
{%- if "widgets" in nb.metadata -%}
<script src="https://unpkg.com/jupyter-js-widgets#2.0.*/dist/embed.js"></script>
{%- endif-%}
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
{% for css in resources.inlining.css -%}
<style type="text/css">
{{ css }}
</style>
{% endfor %}
<style type="text/css">
/* Overrides of notebook CSS for static HTML export */
body {
overflow: visible;
padding: 8px;
}
div#notebook {
overflow: visible;
border-top: none;
}
{%- if resources.global_content_filter.no_prompt-%}
div#notebook-container{
padding: 6ex 12ex 8ex 12ex;
}
{%- endif -%}
#media print {
div.cell {
display: block;
page-break-inside: avoid;
}
div.output_wrapper {
display: block;
page-break-inside: avoid;
}
div.output {
display: block;
page-break-inside: avoid;
}
}
</style>
<!-- Custom stylesheet, it must be in the same directory as the html file -->
<link rel="stylesheet" href="custom.css">
<!-- Loading mathjax macro -->
{{ mathjax() }}
{%- endblock html_head -%}
</head>
{%- endblock header -%}
{% block body %}
<body>
<div tabindex="-1" id="notebook" class="border-box-sizing">
<div class="container" id="notebook-container">
{{ super() }}
</div>
</div>
</body>
{%- endblock body %}
{% block footer %}
{{ super() }}
</html>
{% endblock footer %}

Related

Does PasswordResetConfirmView.py auto populate uid and token?

The view definitely does not populate on my end but password_reset_confirm.html in the demo template folder seems to do that.
password_reset_confirm_form.html
urls.py
path("dj-rest-auth/password/reset/confirm/<str:uid>/<str:token>/",
# TemplateView.as_view(template_name="password_reset_confirm.html"),
PasswordResetConfirmView.as_view(),
name='resend-email-verification'
),
Edit: maybe this webpage here is not the same page in django-rest-auth demo folder.
In django, it is defined as (in django code):
urls.py
path('reset/<uidb64>/<token>/',views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
path('reset/done/',views.PasswordResetCompleteView.as_view(),name='password_reset_complete')
Then, you can customize according to your need and override it by inheriting it in your own views.py file.
Answer credits to GitHub user, riteshbisht.
What I am seeing is UI of browsable API of django rest framework that does not have this functionality for reading url and populating form field unless I tell it to.
For it to do this, I created templates/rest_framework/api.html file and inserted following code inside it:
api.html
{% extends "rest_framework/base.html" %}
{% block style %}
{{ block.super }}
<style>
#btn-link {
border: none;
outline: none;
background: none;
display: block;
padding: 3px 20px;
clear: both;
font-weight: 400;
line-height: 1.42857143;
color: #A30000;
white-space: nowrap;
width: 100%;
text-align: left;
}
#btn-link:hover {
background: #EEEEEE;
color: #C20000;
}
</style>
{% endblock %}
{% block userlinks %}
{% if user.is_authenticated or response.data.access_token %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{% firstof user.username 'Registered' %}
<b class="caret"></b>
</a>
<ul class="dropdown-menu dropdown-menu-right">
{% url 'rest_user_details' as user_url %}
<li>User</li>
<li>
{% url 'rest_logout' as logout_url %}
<form action="{{ logout_url }}" method="post">
{% csrf_token %}
<button type="submit" id="btn-link">Logout</button>
</form>
</li>
</ul>
</li>
{% else %}
{% url 'rest_login' as login_url %}
<li>Login</li>
{% url 'rest_register' as register_url %}
<li>Register</li>
{% endif %}
{% endblock %}
{% block script %}
{{block.super}}
<script type="text/javascript">
var url_elements = window.location.pathname.split('/');
if (url_elements.length >= 3){
var uid = url_elements[url_elements.length - 3];
if (uid !== undefined){
$('input[name=uid]').val(uid);
}
var token = url_elements[url_elements.length - 2];
if (token !== undefined){
$('input[name=token]').val(token);
}
}
</script>
{% endblock %}

Django - Text isn't moving down

I made a class and named it ">My Hero Academy<".
I am trying to make it move down, but it is not moving down.
What is the problem? Image
I am trying to move it lower than my title, then a little left, but it is not moving at all.
<body>
<div class="sidenav2">
<h5>One Piece</h5>
</div>
</body>
</html>
{% endblock %}
My full home page code
{% extends 'main/base.html' %}
{% block title%}
home
{% endblock %}
{% block content %}
<html>
<head>
<style type="text/css">
.sidenav2 a {
padding:6px 8px 6px 216px;
left:100px;
top:100px;
text-decoration: none;
font-size:35px;
color: #818181;
display:block;
}
</style>
</head>
<body>
<div class="sidenav2">
<h5>My Hero Academy</h5>
</div>
</body>
</html>
{% endblock %}
In your css, Change this
.sidenav2 a {
to
.sidenav2 h5 {

Adding style tag in django inherited template

I am new to Django. I want to add just a few lines of styling code in my Django template i.e 'blogs.html' which is already inheriting from a 'base.html' django template.But If I add a style tag and try to give a background image using {%static %} it doesnt work.
Blogs.html
{% extends 'base.html'%}
{% load staticfiles %}
{% block content %}
<style>
body{
margin:0;
padding:0;
}
box1{
height:100vh;
width:100%;
background image:{%static 'images/ps1.jpg'%};
background-size:cover;
}
box2{
height:100vh;
width:100%;
background image:{%static 'images/ps2.jpg'%};
background-size:cover;
}
box3{
height:100vh;
width:100%;
background image:{%static 'images/ps3.jpg'%};
background-size:cover;
}
</style>
<div id="box1">
</div>
<div id="box2">
</div>
<div id="box3">
</div>
{% endblock %}
I am assuming Your {% block content %} {% endblock %}
is in html body but that CSS code should be in head. That's why it's not working.
If you really need this, then you can create a block on base.html head section.
Something like this
<head>
{% block mycss %} {% endblock mycss %}
</head>
and the in inherited html
{% extends 'base.html'%}
{% load staticfiles %}
{% block mycss %} <style> Your entire css </style> {% endblock %}
{% block content %}
Body Part
{% endblock %

django endblock syntax error

I am currently following a Django tutorial and I believe that I followed it precisely however I am getting this syntax error. It is saying that {% endblock %} isn't working. Not really sure why this is incorrect. I am trying to create a partial view or template inheritance and plug it into the base.html
My error:
Invalid block tag: 'endblock'
Request Method: GET
Request URL: http://127.0.0.1:8000/articles/all/
Django Version: 1.6
Exception Type: TemplateSyntaxError
Exception Value:
Invalid block tag: 'endblock'
Error during template rendering
In template /Users/bradfordli/Development/django-brad/django_test/article/templates/articles.html, error at line 25
Invalid block tag: 'endblock'
15 {% endfor %}
16 {% else %}
17
18 <p> None to show!</p>
19
20 {% endif %}
21
22 </body>
23 </html>
24
25 {% endblock %}
26
My articles.html
{% extends "base.html" %} <!-- this templates extends the base.html template -->
(% block content %)
<html>
<body>
<h1>Articles</h1>
{% if articles.count > 0 %}
{% for article in articles %}
<div>
<h2>{{article.title}}</h2>
<p>{{article.body|upper}}</p>
</div>
{% endfor %}
{% else %}
<p> None to show!</p>
{% endif %}
</body>
</html>
{% endblock %}
My base.html
<!-- Base of every pate in the side-->
<!DOCTYPE html>
<html lang = "en">
<head>
<title>{% block title %} My Base Template {% endblock %}</title>
<style type="text/css">
body {
text-align: center;
}
#page {
width: 960px;
text-align: left;
margin: 10px auto 20px auto;
background-color: #0c0c0c;
}
#sidebar {
float: left;
width: 200px;
border: 1px solid #000;
}
#content {
float: left;
width: 600px;
border: 1px solid #f00;
padding: 10px;
}
</style>
</head>
<body>
<div id = "page">
<div id = "sidebar">
<!-- This block of the page is named "sidebar"
Also anything between can be substituded by other templates
as long as they refer to sidebar as a block within their template
-->
{% block sidebar %}
<ul>
<li> Articles</li>
<li>Admin</li>
</ul>
{% endblock %}
</div>
<div id = 'content'>
<!-- This block of the page is named "content"-->
{% block content %} This is the content area {% endblock %}
</div>
</div>
</body>
</html>
I don't see any endblock here:
<title>{% block title %} My Base Template</title>
Change the following:
(% block content %) => {% block content %}

Django template extend issue

When I use {% extends %} tag its not pulling through my standard html. Is there something am missing am new to Django template tags. I want to add the Standard,html into my index.html file which also resides in the templates folder.
My index file in the template folder:
{% extends "Standard.html" %}
{% block maincontent %}
{% block headcontent %}
<link rel="stylesheet" type="text/css" href="/media/css/Panels.css" />
<link rel="stylesheet" type="text/css" href="/media/css/HostOverview.css" />
{% endblock %}
<script>
function disaT(c,f){
if(c.checked){f.txt1.disabled=false;
f.submit.disabled=false;
}
else{f.txt1.disabled=true;
f.submit.disabled=false;
}
}
</script>
<style>
a:link {
color: #39F;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #63C;
}
a:hover {
text-decoration: none;
color: #CCC;
}
a:active {
text-decoration: none;
color: #000;
}
</style>
<div style="display:none" id="dialog" title="Disable Your Account?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This will disable your account and log you out. You won't be able to log back in. Are you sure you want to continue?</p>
</div>
<h1></h1>
<form name="logger" action="" method="post">
<label>Input : </label><textarea name="txtexec" id="txtexec" cols="50"/>{{ txtexec }}</textarea> <input type="submit" name="execute" value="Execute" /><br /><br />
<label>Pattern Input : </label><input name="txtpattern" id="txtpattern" type="text" size="100" value="{{ txtpattern }}" /><br />
<label>Result : </label><br />
</form>
<P>Discover</P>
<pre>
{{ file_content }}
</pre>
<P>Console output</P>
<pre>
{{ Output_content }}
</pre>
<form name="checkin_form" action="#" method="post" enctype="multipart/form-data"><br><br>
Full pattern : <span style="color:#000; font-size:10px; background:#CCC;" >{{ session_fullpattern }}</span><br><br>
<label>Check In : </label><input type="checkbox" onclick="disaT(this,this.form)"><br>
<label>Enter pattern name : </label><input name="txt1" type="text" disabled="true"> <input type="submit" name="submit" value="Submit" disabled="true" />
</form>
<div style="clear:both;" />
{% endblock %}
My standard.html page:
{% extends "Base.html" %}
{% block head %}
<link rel="stylesheet" type="text/css" href="/media/css/Standard.css" />
<link rel="stylesheet" type="text/css" href="/media/css/Menu.css" />
<link rel="stylesheet" type="text/css" href="/media/css/Tooltip.css" />
<link rel="Stylesheet" type="text/css" href="/media/css/custom_theme/jquery-ui-1.7.2.custom.css" />
<script type="text/javascript" src="/media/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/media/js/jquery-ui-personalized-1.6rc6.min.js"></script>
{% block headcontent %}{% endblock %}
{% endblock %}
You're nesting blocks inside each other, which is rarely the right thing to do.
Your index.html should start like this:
{% extends "standard.html" %}
{% block headcontent %}
<link rel="stylesheet" type="text/css" href="/media/css/Panels.css" />
<link rel="stylesheet" type="text/css" href="/media/css/HostOverview.css" />
{% endblock %}
{% block maincontent %}
... etc
but then you also need a place for maincontent to go in standard.html:
{% extends "Base.html" %}
{% block head %}
.... content ...
{% endblock %}
{% block headcontent %}{% endblock %}
{% block maincontent %}{% endblock %}
Your inheritance and naming is way of. Examine the template language documentation. The example below should give you an idea aswell.
base.html
<html>
<head>
<!-- this will always be inherited -->
{% block head %}
<!-- this can be overruled -->
{% endblock %}
</head>
<body>
<!-- this will always be inherited -->
{% block body %}
<!-- this can be overruled -->
{% endblock %}
</body>
</html>
page.html
{% extends "base.html" %}
{% block head %}
<!-- Hello I am overwriting the base head, but not touching it's body. -->
{% endblock %}

Categories

Resources