How to play audio in Django ? - python

How To use the audio file of the local system to play in django?
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<link href="{% static 'css/result_style.css' %}" type="text/css"
rel="stylesheet"/>
<link rel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<div class="container" align="center"><br><br><br>
{% load custom_filters %}
<h2>{{summary}}</h2>
<br>
This part is working fine while playing this part in simple html code
<p>Click on the audio To Listen Your Summary</p>
<audio controls>
<source src="D:\textanalysis\audio_file.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div>
</body>
</html>

Related

No changes done by static function in HTML in Django

Html File
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="{% static "css/style.css" %}"/>
</head>
<body>
<h1>This is from index.html</h1>
{{help_me}}
<img src="{% static "images/DjangoGuitar.jpg" %}" alt="sorry text not loaded">
</body>
</html>
CSS file
h1{
color: red;
}
Output:
This is from index.html
Welcome to the page sorry text not loaded
Have you tried enclosing the css/style.css part in single quotes to see if it works? Like so <link href="{% static 'css/style.css' %}" rel="stylesheet">.
The double quotes at "css/style mean you have closed the first one beginning at href="{%

How to change the css of template in django?

I import a bootstrap template in django, the index.html is:
{% load staticfiles %}
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Business Casual - Start Bootstrap Theme</title>
<!-- Bootstrap Core CSS -->
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{% static 'css/business-casual.css' %}" rel="stylesheet">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700,100italic,300italic,400italic,600italic,700italic" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<div class="brand">university search</div>
<div class="address-bar">3481 Melrose Place | Beverly Hills, CA 90210 | 123.456.7890</div>
...
All my staticfiles in the folder static , the setting.py file is:
STATIC_URL = '/static/'
I want to modifie the image of bacground of template but doesn't work , the css file is :
body {
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
background: url('/home/hadoop/PROJET/static/img/theboatthatrocked.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cov
but it does not change anything, you can help me
You can try it with this tutorial:Config static files in Django projects

Implementing 404 page in Django, but receiving error

I'm trying to implement my 404.html page into my django project, and coming across this error. Everything else is complete in my project, so I'm eager to get this last piece done! any help is greatly appreciated. included the 404.html and head_css.html file. please let me know if you need to see anything else.
Can anyone help with this?
My 404.html code:
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="404 Page not found">
<meta content="width=device-width, initial-scale=1, user-scalable=no" name="viewport">
<title>Codes For Anyone</title>
<link rel="shortcut icon" type="image/x-icon" href="{% static 'themes/images/favicon.ico' %}">
<!-- Google icon -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
{% include 'landing/head_css.html' %}
</head>
<body class="body-custom body-404page">
<div class="errorpage">
<div class="wrapper">
<div class="container">
<div class="content-primary">
<h1 class="title">Page Not Found</h1>
<p class="description">The page you are looking for was moved, removed, <br>
renamed or might never existed.</p>
<div class="section-footer">
Back To Homepage
Report Error
</div>
</div><!-- content-primary -->
</div><!-- container -->
</div>
</div>
<!-- chitika ad code -->
<div class=" container-fluid full-width-container contact">
<script type="text/javascript">
( function() {
if (window.CHITIKA === undefined) { window.CHITIKA = { 'units' : [] }; };
var unit = {"calltype":"async[2]","publisher":"andrewdiemer","width":550,"height":250,"sid":"Chitika Default"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
</script>
<script type="text/javascript" src="//cdn.chitika.net/getads.js" async></script>
</div>
<!-- end ad code -->
</div>
<!-- Scripts Starts -->
{% include 'landing/javascript.html' %}
<script>
$(document).ready(function() {
var sPath=window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
$(".pmd-sidebar-nav").each(function(){
$(this).find("a[href='"+sPage+"']").parents(".dropdown").addClass("open");
$(this).find("a[href='"+sPage+"']").parents(".dropdown").find('.dropdown-menu').css("display", "block");
$(this).find("a[href='"+sPage+"']").parents(".dropdown").find('a.dropdown-toggle').addClass("active");
$(this).find("a[href='"+sPage+"']").addClass("active");
});
});
</script>
<!-- Scripts Ends -->
</body>
</html>
head_css.html:
{% load staticfiles %}
<!-- Bootstrap css -->
<link rel="stylesheet" type="text/css" href="{% static 'assets/css/bootstrap.min.css' %}">
<!-- Propeller css -->
<!-- build:[href] assets/css/ -->
<link rel="stylesheet" type="text/css" href="{% static 'assets/css/propeller.min.css' %}">
<!-- /build -->
<!-- Propeller date time picker css-->
<link rel="stylesheet" type="text/css" href="{% static 'components/datetimepicker/css/bootstrap-datetimepicker.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'components/datetimepicker/css/pmd-datetimepicker.css' %}" />
<!-- Propeller theme css-->
<link rel="stylesheet" type="text/css" href="{% static 'themes/css/propeller-theme.css' %}" />
<!-- Propeller admin theme css-->
<link rel="stylesheet" type="text/css" href="{% static 'themes/css/propeller-admin.css' %}">

flask : encountered unknown tag endif though tags were specified

I'm working on a flask-sqlalchemy webapp that requires login.
The logout button should be visible on the pages only if user is logged in.
So all those pages extend layout.html file which looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Login</title>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
{% block head %} {% endblock %}
</head>
<body>
{% block body %}
<style type="text/css">
#footer {
position : absolute;
bottom : 0;
}
</style>
{ % if session['logged_in'] %}
<div id="footer" style="width:300px;height:100px">Logout</div>
{% endif %}
{% endblock %}
<script src="{{ url_for('static', filename='js/jquery.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
</body>
</html>
The error I'm getting is :
TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was
looking for the following tags: 'endblock'.
The innermost block that needs to be closed is 'block'.
Although the endblock and if tags have been specified
Please help me fix this
Try removing the space between { and % in
{ % if session['logged_in'] %}
so that it becomes
{% if session['logged_in'] %}

XML Parsing Error: mismatched tag. Expected: </link>, Django

I am working with a django template. the head of the template is:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Landing Page - Start Bootstrap Theme</title>
<!-- Bootstrap Core CSS -->
{% load staticfiles %}
<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{% static "css/landing-page.css" %}" rel="stylesheet">
<!-- Custom Fonts -->
<link href="{% static "font-awesome-4.2.0/css/font-awesome.min.css" %}" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
My view contains:
def index(request):
t = loader.get_template('app1/index.html')
c = RequestContext(request, {})
return HttpResponse(t.render(c),content_type="application/xhtml+xml")
How can I fix the error in the screenshot?
This is not a valid XML tag:
<link href="{% static "css/landing-page.css" %}" rel="stylesheet">
Instead, it should be:
<link href="{% static "css/landing-page.css" %}" rel="stylesheet" />
This is because, according to XML specs, any tag has to be either closed with its pair or self-closed by including slash (/) at the and of opening tag.
Most browsers understand this, but, speaking strictly, this is incorrect.
Also, if you have any <hr>, <br> or similar single tags, you'll have to fix them all as well, i.e. <hr />, <br />
See this list: http://xahlee.info/js/html5_non-closing_tag.html.

Categories