Display source code as text


#1

Hi everyone,

I’m pretty new to web development, and I’ve run into an issue that I don’t really know enough terminology about to look in the right places.

I have a file foo.py that I have on my site, and when someone accesses that file on the web, I want to make it so that it displays the source code of the file as it would a .txt file. However, when I try to navigate to this page, I instead get a 500 Internal Server Error.

Upon checking my server log, I see the following error:

[error] [client XXX.XXX.XXX.XXX] Premature end of script headers: foo.py

Does anyone know how to fix this? Even just letting me know what to search for would be appreciated.


#2

Rename or copy the file to .txt extension.

for php, i have a line of code that can be included in the file so that you can add a URL extension of “?sce=view” to the end of the URL to make it viewable. Don’t know if there is an equivent for python tho.


#3

Add that directive to a .htaccess file in your source directory.

Result : http://sxi.sabrextreme.com/python


#4

Fantastic! It works now. Thanks!