Pyramid server not serving flash files - python

I am running this python pyramid server. Strangely, when I moved my server code to a different machine, pserve stopped serving flash videos in my static folder. Whereas it serves other static files, like images, fine ! What could be a reason for this ?

Pyramid's static views serve up files with a content-type determined via python's mimetypes module. Most likely you'll need to add support for the extra video types to your installation at startup. Specifically something along the lines of the following, somewhere in your code.
import mimetypes
mimetypes.init()
mimetypes.add_type(...)

I possibly ran into a similar problem on my pyramid app. I'm using TinyMCE and had placed the files in the static folder. Everything worked on my dev server, but moved to test and prod and static .html files related to TinyMCE couldn't be found.
My web host had me add a symlink basically I think hardcoding to the server software (nginix in this case) the web address to my static HTML to the server path and that worked.
I'll have to check out the mimetypes thing, though, too.

Related

How to turn off directory listing when serving static content from web.py over cheroot

I am running a web.py application using the Cheroot web server included with web.py, and directory listing for static files seems to be enabled by default. I have tried reviewing the documentation for the Cheroot web server but don't see a way to turn off directory listing. Any help is appreciated!

An easy way to show images in Django on deployment (DEBUG=false)

I am using DJango 1.8 and python 3.4.3, and I have been running my app on Debug mode, and found a way to show images inside a directory configured on MEDIA_ROOT, this was my first question and the solution I have found: How to upload and show images in DJango. But reading the docs I found that that solution is not suitable for a served app, so, if I stop using "Debug=True" the images will not be displayed, and I have to use one of the options exposed on this link: Static files on deployment but I don't have money to pay another server, I just can pay my hosting on pythonanywhere, and for the option to use the same server for the images, I don't have idea how to automate the collectstatic and also don't know how to trigger it when an user uploads a new image.
I have used ASP.NET and PHP5 and I didn't had problems with the images in none of them, so, I have two questions:
Is there an easy way to show images URL's?
Is there a high risk security problem if I deploy my app with DEBUG=True?
I hope you can help me, because I find this ridiculous, probably is for better security, but it just not make sense for a framework, instead of making the work easier it make it more difficult and stressful.
Django runserver is not intended for serving up static files in a production environment. It should be limited to development and testing environments.
If you are intending to use django's runserver to server up static files with DEBUG=False then use the --insecure flag.
You should never deploy a site with DEBUG = True due to security implications.
Static files and media assets are 2 different things.
Static Files
Static files are things like images you created and files that come with 3rd party apps you have installed (e.g. django-cms). These files include images, css and javascript files etc.). So you need to have a settings.STATIC_ROOT for this.
python manage.py collectstatic collects static files from different locations and puts them all in a single folder.
Media Files
Media files are things the user uploads (e.g. photos, documents etc.). So you have a settings.MEDIA_ROOT for this. collecstatic won't do anything to media files, they will just be there already once the user uploads them.
Serving up static and media files in production
Frameworks like Django aren't going to cover automatic production server configuration - that is something else you will have to learn unfortunately.
There are a lot of good guides around e.g. this one to help you get started serving media and static files in production.
Regarding server costs, I'm sure you can find a host to give you some free credit, or pay $5/month for a server somewhere... try lowendbox
Here is a guide from pythonanywhere regarding media and static files: https://help.pythonanywhere.com/pages/DjangoStaticFiles/
1) in urls.py add:
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
and open url http://myhost.com/media/
2) Never deploy a site into production with DEBUG turned on, DEBUG=True is a security issue,

Issue launching web.py webserver from another directory

So I'm running web.py using the development server (not apache) and I'm having an issue running the webserver on startup. The real issue is that I can only successfully run the webserver from its own directory. The webserver launches and runs, but none of the static files are properly loaded. So if my working directory is /home/user/webserver , then I can run code.py and the statics from /home/user/webserver/static load fine. However, if I'm in /home/user directory, or any other directory, they won't load. I know it's an issue of relative path names, but I don't believe I can just give the absolute path names of the static files as that would pose security risks and I don't believe web.py allows that. I've been searching for a while for a solution, and I think it involves setting up a static file mapping from the url /static to the directory path to /home/pi/webserver/static, but I'm not sure how to do that. Any help is greatly appreciated, or a link to an already answered question like this. Thanks

Django in IIS not loading Static Files

I successfully integrated django in IIS 7.5 (server loads django1.6.5 using python2.7) but it doesn't load static files(CSS, JS), when I run manage.py runserver static files were loaded though. Am I missing something. I followed this tutorial in YouTube https://www.youtube.com/watch?v=kXbfHtAvubc. Thanks!
That video works great on my static file serving. Here is my environment: Python 2.7 Django 1.7 on Windows Server IIS 7.5
If you stick on steps, there shouldn't be any problem. Make sure you remove "Django Handler" in staticapp which is # 17:51 on that video. And check whether there is a static file handler in handler mappings. After you check your steps and make sure everything is right, you may try another way below to serve static file.
You may add a virtual directory to serve static file.
[How to fetch static CSS files with django on IIS?

django css and js files gzip compression on heroku

I am trying to compress my css and js files and serve as gzip file, but with no success.
I have tried all methods, django-pipeline, django-compressor etc.
I got django-compressor to create the gzip files but I am not sure how to serve them. I use GzipMiddleaware to compress and serve my html files.
Can any one please write step by step guide on how gzip and serve static files on heroku django.
Sorry to ask for detailed steps, I am not asking to be spoon fed, but am stuck with this issue for almost 24 hours now, tried n number of solutions, but none seems to work.
FYI, I am using django-1.5
Thanks in advance for your help
You should seriously consider uploading your static files to s3 as well. Django is really not cut out for serving files, and it will consume precious resources on your app server to do so.
Here's some great reasons for using s3 for staticfiles. http://blog.doismellburning.co.uk/2012/07/14/using-amazon-s3-to-host-your-django-static-files/
Here's a article explaining how to get S3 to serve gzipped resources: http://www.jamiebegin.com/serving-compressed-gzipped-static-files-from-amazon-s3-or-cloudfront/
Here's a storage backend that will collectstatic to s3.
You could probably easily write a storage backend that gzips and upload to s3 by subclassing this backend and django-compressor's backend.
I had the exact same issue. I was using grunt but found there was a lot of extra config etc etc etc then I found django-compressor which is AWESOME!
But I deploy to Heroku which doesn't gzip anything and relys on the app to do it.
I couldnt find any wsgi wrapper that served pre-compressed gzip files, so I extended dj-static to do it for me. Check out my fork of dj-static which includes the additions. Basically it will check for a corresponding static filename that ends in .gz and if it finds it, it will serve it instead. I use this for my Heroku projects.
https://github.com/hdickson/dj-static
To test on your dev server if you run the django built in web server be sure to run it with the --nostatic command line switch. ie python manage.py runserver 0.0.0.0:80 --nostatic

Categories

Resources