0

Im trying to display the contents of the text file with no luck. I have tried php which looked like an easy way to do it with no luck

base.html

{% load i18n static %}

<!DOCTYPE html>
<html>
{% load static %}
<head>
    <head lang=en>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

</head>
<body>
    <div >
            <div class="jumbotron" style="background-color: white; padding: 1.5rem;margin-bottom:i 100.5rem">
                    <div class="row">
                            <div class="col-md-3"><a href="/"><img src="{% static 'css/images/hadoop.png' %}"</a></div>
                            <div class="col-md-6">
                                    <h2>Impala Query Metrics</h2>
                                    <hr class="my-2" href="{% url 'impala' %}">

                            </div>

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$f = fopen("pathtofile/test.txt", "r");
// Read line from the text file and write the contents to the client
echo fgets($f);
fclose($f);
?>

I have also tried

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
readfile("pathtofile/test.txt");
?>

Also:

<?php
include("pathtofile/test.txt");
?>

Im not getting any errors nor seeing any results

user3508766
  • 509
  • 1
  • 10
  • 26

2 Answers2

0

There are a few issues here; hopefully this provides some thoughts on where to go.

First, it appears that you want to run PHP code inside an HTML file, as the name of the file is base.html. The PHP interpreter is not configured (by default) to allow this, as it will only run files with the php extension. The fix for this would be to tell your web server to associate html files with the application/x-httpd-php mime type, so html files are ran through the php interpreter.

Second, I noticed the question is tagged with django, which is a Python framework. Do you have a PHP interpreter installed on the server? In order to execute PHP code, you'll need a PHP interpreter, which Python is not. To fix this, you would need to install a PHP interpreter (https://secure.php.net/ - right sidebar)

Third, should you really do this? Python and PHP both serve the same need, to provide server side processing to a web site. I would argue that you should use one or the other, but not both. Since you're already running Django, I would advise that you look for the Python-esque way of accomplishing a file include.

Goldentoa11
  • 1,660
  • 2
  • 17
  • 28
  • Here's an answer showing how to print a file in python. https://stackoverflow.com/questions/18256363/how-do-i-print-the-content-of-a-txt-file-in-python – Goldentoa11 Feb 27 '18 at 16:27
  • Great. This makes much sense thank you for the explanation. I will try to find something with python – user3508766 Feb 27 '18 at 16:34
0

assuming your file is text-file and you want the a html file that your data wrapped inside a div or so then : I'm not a python fan but for python some links , not exactly same title but may good for beginning:

https://python-forum.io/Thread-read-text-file-using-python-and-display-its-output-to-html-using-django

Django displaying upload file content

https://djangobook.com/generating-non-html-content/

or in php: 0.php

<!DOCTYPE html>
<html>
<body>
 <div class="content-wrapper">
  <?php
   echo file_get_contents( "YOURFILE" ); // get the contents, and echo it out.
  ?>
 </div>
</body>
</html>
nullqube
  • 2,689
  • 18
  • 18