Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSS not linking with CGI script
#1
hi,
i am new in python cgi.I try to code cgi with python.i can not linked with css file with python script.The css file name is style.css.
my code is here :

#!/usr/bin/python3.5


print("Content-type: text/html\r\n\r\n")
print("<!doctype html>")
print("<html>")
print("<head>")
print("<title>")
print("Cgi-python")
print("</title>")
print("<link rel='stylesheet' type='text/css' href='/style.css'>")
print("</head>")
print("<body>")

print("<h1>My name is zzzzzz</h1>")

print("</body>")
print("</html>")
this is my python cgi script...

here i tell you that css file locate at the same directory where python script located.
css file contain :

*{
    padding: 0px;
    margin: 0px;
    font-size: 20px;
}

h1{
    color: blue;
}
what is the problem with my script.Why i can
Quote
#2
You should really use python's docstrings, then you dont need to print each line such as

html = """Content-type: text/html

<html>
<head>
<link type="text/css" rel="stylesheet" href="/cgi-bin/styles.css" />
</head>
<body>
<select>
    {OPTIONS}
</select>
<p>
My text
</p>
</body>
</html>
""".format(
        OPTIONS=html_list,
        )
print(html)

It also makes it quicker and easier to plugin a value like OPTIONS here. NOTE: you do need the blank line on line 2.


and you cant link the script as if its in the same directory. You have to make the path to from root. Most likely on a linux server your cgi would be in a cgi-bin directory, so even though the scripts are in the same directory, you still need to link it from the root directory. 

so lets say html is the root
/var/www/html

and your scripts live here
/var/www/html/cgi-bin

even though both CSS and your cgi script are in cgi-bin, you need to use 
<link type="text/css" rel="stylesheet" href="/cgi-bin/styles.css" />
instead
*Describe the environment in which it occurs.                                    *Describe the symptoms of your problem clearly.
*Describe the research you did to try and understand the problem.      *Describe the goal, not the step. 
*Use meaningful, specific subject headers                                          *Write in clear, grammatical, correctly-spelled language
*Describe the problem's symptoms, not your guesses                         *Describe your problem's symptoms in chronological order
*Describe the diagnostic steps you took to try and pin down the problem yourself.
*Describe any possibly relevant recent changes in your computer or software configuration. 
*Provide a way to reproduce the problem in a controlled environment.
Quote
#3
sorry css not working .....again..

#!/usr/bin/python3.5
import cgi

html = """Content-type: text/html\r\n\r\n
 
<html>
<head>
<link type="text/css" rel="stylesheet" href="/cgi-bin/cgi/style.css" />
</head>
<body>
<h1>
My text
</h1>
</body>
</html>
"""
print(html)
i cant figure out whats the problem
Quote
#4
Please sto using CGI in Python,it's dead after WSGI.

Use Flask
Eg.
pip install flask
Folder setup:
foo\
app.py
  templates\
  index.html
  static\
    css\
    style.css
app.py
from flask import Flask, render_template

app = Flask(__name__)
@app.route("/")
def bak_image():
    return render_template("index.html")

if __name__ == '__main__':
    app.run()
index.html
<html>
  <head>
    <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/style.css') }}" />   
  </head>
  <title>
    Wsgi trough Flask
  </title>  
  <body>
    <h1>My name is zzzzzz</h1>
  </body>
</html>
style.css
*{
  padding: 0px;
  margin: 0px;
  font-size: 20px;
}
 
h1{
  color: blue;
}
Run python app.py.
In browser http://127.0.0.1:5000/
Quote
#5
(Nov-11-2016, 03:00 PM)snippsat Wrote: Please sto using CGI in Python,it's dead after WSGI.
that doesnt stop people from using it

if this is your path
/cgi-bin/cgi

then it should work. You might want to check the log files for a better description to why it might not be working.
*Describe the environment in which it occurs.                                    *Describe the symptoms of your problem clearly.
*Describe the research you did to try and understand the problem.      *Describe the goal, not the step. 
*Use meaningful, specific subject headers                                          *Write in clear, grammatical, correctly-spelled language
*Describe the problem's symptoms, not your guesses                         *Describe your problem's symptoms in chronological order
*Describe the diagnostic steps you took to try and pin down the problem yourself.
*Describe any possibly relevant recent changes in your computer or software configuration. 
*Provide a way to reproduce the problem in a controlled environment.
Quote
#6
What does "it doesn't work" mean? Do you get errors in your browser's development console? When you browse to the file in your browser, does it download?
metulburr likes this post
It's dangerous to go alone!  Take this: https://docs.python.org/3/library/index.html
HackerRank seems neat: https://www.hackerrank.com/nilamo
Quote
#7
i use lampp server at ubuntu 15.10.
the css path is :
/cgi-bin/cgi/
and i write it on my code but not change anything

(Nov-12-2016, 06:41 AM)x64 Wrote: i use lampp server at ubuntu 15.10.
the css path is :
/cgi-bin/cgi/
and i write it on my code but not change anything
where i found the log file
Quote
#8
view the apache error log, and see what it says when you try to access that page from a browser
*Describe the environment in which it occurs.                                    *Describe the symptoms of your problem clearly.
*Describe the research you did to try and understand the problem.      *Describe the goal, not the step. 
*Use meaningful, specific subject headers                                          *Write in clear, grammatical, correctly-spelled language
*Describe the problem's symptoms, not your guesses                         *Describe your problem's symptoms in chronological order
*Describe the diagnostic steps you took to try and pin down the problem yourself.
*Describe any possibly relevant recent changes in your computer or software configuration. 
*Provide a way to reproduce the problem in a controlled environment.
Quote
#9
As you have wrote it ( "/style.css" ) the css file is located in /. That means the root directory of the whole system. If it's located at the same directory it should be "style.css" or "./style.css". Not sure for the second one.
metulburr likes this post
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)