My problem is that the browser downloads the pdf instead of displaying it.
I tried some solutions from this site (for example) but none of them worked for me.
I use this code in my html file and nothing else:
{% load static %}
<body>
<object data="test.pdf" type="application/pdf" title="SamplePdf" width="500" height="720">
<embed src="{% static 'test.pdf' %}" >
</object>
</body>
Ideas?
Displaying PDF has nothing in common with Django, you can handle it with pure HTML:
Recommended way to embed PDF in HTML?
Have you tried:
<embed src="{% static 'test.pdf' %}" width="500" height="375"
type="application/pdf">
?
Related
I'm trying to pull the link from the database in the src part, but I couldn't.
im using django. images are in s3 storage. i append link to sqlite database in django. normally, {{project.ac}} is working. but <img src=> is not working.
JİNJA TEMPLATE
CODE
<figure class="glitch-filter-example">
<figcaption class="glitch-filter-example__heading">{{ project.ac }}</figcaption><br/><br/>
<img src={{ project.image }}>
<img src={{ project.image2 }}>
<p class="glitch-filter-example__filtered-text">HTML text</p>
</figure>
<script src="{% static 'icerik/js/script.js' %}"></script>
PAGE SOURCE
<figcaption class="glitch-filter-example__heading">MY TEXT</figcaption><br/><br/>
<img src=>
<img src=>
Trying to implement Google Places API, to look for businesses.
I am trying to break down the result in different sections (name,address,city...) to stick it in a form.
Doing a bit of research, I have actually found the ultimate code to copy. However, I am using Django and I am too much of a newbie in coding, to understand how to alter the code to make it work with the framework. (https://jsfiddle.net/geocodezip/ep5aw171/1/)
Here is the code I have:
js file
function initMap(){
autocomplete = new google.maps.places.Autocomplete(document.getElementById("input"),{
componentRestrictions: {'country':['uk']},
fields: ['name','geometry'],
types:['establishment']
});
autocomplete.addListener('place_changed');
}
html
<html>
<h1>Google Places API Test</h1>
<body>
<input id="input" placeholder="*Name API" style="height: 75px; width:1000px">
<script src="{% static 'google_places_names.js' %}"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=xxx&libraries=places&callback=initMap"></script>
</body>
</html>
This bit works. When I type an address, I get the address of the what I am looking for (see screenshot)
Given that I am planning to use a django form to capture the information, I am assuming the html to look like this:
<html>
<h1>Google Places API Test</h1>
<body>
<input id="input" placeholder="*Name API" style="height: 75px; width:1000px">
<form id="GoogleAPI" method="POST" action="{% url 'google_api_test'%}">
{% csrf_token %}
<label for="address" class="hidden-el" hidden>Address</label>
{{form.name}}
<label for="address" class="hidden-el" hidden>Address</label>
{{form.address}}
...
</form>
<script src="{% static 'google_places_names.js' %}"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=xxx&libraries=places&callback=initMap"></script>
</body>
</html>
Looking at the different answers on the topic, there seems to be lot of code to write,so I am expecting anyone to do this here. But I wondering if someone may know a link to a Django tutorial for Google API for businesses (establishment). Found a few online, but they do not cover establishements and the approach appears to be different.
I understand the next step would be to call is to call autocomplete.getPlace() within a function. But all attempts I made proved to unsuccessful.
Would be grateful if anyone had any pointers!
according to django's documentation:
When you raise Http404 from within a view, Django loads a special view devoted to handling 404 errors. By default, it’s the view django.views.defaults.page_not_found(), which either produces a very simple “Not Found” message or loads and renders the template 404.html if you created it in your root template directory.
, i created a 404.html file in the root template directory.
when the app raises a 404 error, this 404.html that i created before, will shown, but it's css and it's background image not load.
this is the 404.html file code:
<!DOCTYPE html>{% load staticfiles %}
<html>
<head>
<title>not found</title>
<link rel="stylesheet" href="{% static 'css/error_style.css' %}"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
</head>
<body class="color-404">
<div id="error">
<img class="error-image" src="{% static 'img/404.jpg' %}"/>
</div>
<div class="error-router">
<i class="fa fa-home"></i>
<i class="fa fa-arrow-left"></i>
</div>
</body>
</html>
how can i fix this problem?
tanx
Not really an answer to your question, but in general it is best to not have external .js and .css files in error-pages.
Include it in the page itself, to avoid situations like this, where for some reason the error-page produces an error. Use a single static page.
I found what was the problem.
because i set DEBUG to False, django's built-in webserver, was not served staticfiles.
I'm trying to get a Google AdSense ad to display on my mobile website. I am using Django to serve my web pages and I'm using JQuery Mobile to display and format the content. I've followed these blog instructions on a static html page and the ad shows up fine. When I use the exact same code in my base template, the mobile ad does not show. When I compare the HTML source code they look exactly the same and all the links work exactly the same. Is there something Django injects into the header that would keep the ad from displaying? The HTML source is as follows:
<html>
<head>
<title>Test AdSense</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css"/>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-XXXXXXXXXXXXXXXXXX";
/* LTC MobileHeader */
google_ad_slot = "XXXXXXXXXXXX";
google_ad_width = 320;
google_ad_height = 50;
//-->
</script>
</head>
<body>
<div id="Div1" data-role="page" data-ajax="false">
<header data-role="header" data-position="fixed">
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<h1>Index Page</h1>
</header>
<section data-role="content">
to Page 2
</section>
<footer data-role="footer" data-position="fixed"></footer>
</div>
</body>
</html>
I decided to upload the code to my staging system system which runs on Ubuntu and the ads show up fine. There is something going on with my development environment which runs on windows that is blocking the call to Google.
I want to print an image by using a img src tag in a Django template file "base.html":
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Foto</title>
</head>
<body>
<h1>My helpful timestamp site</h1>
<img src="google.png" / >
<hr>
<p>Made by ... </p>
</body>
</html>
In views.py I define:
def hello(request):
return render_to_response('base.html')
But the image does not show up in the browser. If I open it as a simple html file, it shows up in the browser.
In recent versions of django
<img src="{% static 'path/to/image.ext' %}"/>
That happens because Django does not know the path to this image.
Make a folder named static/, and then a folder named images/ in your project root(where your settings.py file resides).
my_project/
my_project/
settings.py
static/
images/
google.png
And then change it to:
<img src="{{STATIC_URL}}images/google.png" / >
More here.
You have got to add load static tag in the beginning of your Django template, best luck with below code.
{% load static %}
<img src="{% static 'path/to/image.ext' %}"/>