简体   繁体   中英

embedding external css and script in python cgi shows 500 Internal Server Error

My program directory:

     xampp
       |- cgi-bin
            |- home.py
            |- style.css
            |- script.js

In home.py i embeded style.css and script.css

print "Content-type:text/html\r\n\r\n"
print '<html>'
print ' <head>'
print '     <meta http-equiv="content-type" content="text/html; charset=UTF-8">'
print '     <title>Home</title>'
print '     <link rel="stylesheet" type="text/css" href="style.css">'
print '     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">           </script>'
print '     <script src="script.js"></script>'

But it doesn't work and in my console it shows :

"NetworkError: 500 Internal Server Error - http://localhost/cgi-bin/script.js" & "NetworkError: 500 Internal Server Error - http://localhost/cgi-bin/style.js"

Another Case:

I tried /style.css and /script.js while embedding:

RESULTS

"NetworkError: 404 Not Found - http://localhost/style.css" "NetworkError: 404 Not Found - http://localhost/script.js"

tried /cgi-bin/style.css and cgi-bin/script.css shows the 500 internal server error with absolute path

Tried using absolute path: http://localhost/cgi-bin/style.css and http://localhost/cgi-bin/script.js also shows the same 500 internal server error

Whereas jquery is working fine with CDN.

is there something i haven't configured or is there some other way around ?

Javascript and CSS should not be in a cgi-bin, which serves files (typically with .cgi or - in your case - .py extensions) as cgi scripts . Instead, .js and .css files are usually in the website root folder or (for a Python app) served as static files in my_site_root/html/js/ from somewhere public-readable by the app like my_app/public/ .

So your cgi-bin shouldn't serve files directly readable via a web browser, like Javascript and CSS files. XAMPP will be set up that way by default.

The CDN URL will always work because it's making an http call to an external server - it doesn't look in your locally-served XAMPP install.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM