Static Media Server (Tango with Django)

147 views
Skip to first unread message

Max Nathaniel Ho

unread,
Oct 13, 2014, 7:39:26 AM10/13/14
to django...@googlegroups.com
Hi all,

I am going through this tutorial on Tango with Django - http://www.tangowithdjango.com/book/chapters/templates_static.html

I extracted the specific part of the tutorial as seen in BOLD.

4.4. The Static Media Server

Now that you can dispatch static files, let’s look at uploading media. Many websites provide their users with the ability to do this - for example, to upload a profile image. This section shows you how to add a simple development media server to your Django project. The development media server can be used in conjunction with file uploading forms which we will touch upon in Chapter 8.

So, how do we go about setting up a development media server? The first step is to create another new directory called media within our Django project’s root (e.g.<workspace>/tango_with_django_project/). The new media directory should now be sitting alongside your templates and static directories. After you create the directory, you must then modify your Django project’s urls.py file, located in the project configuration directory (e.g.<workspace>/tango_with_django_project/tango_with_django_project/). Add the following code to the urls.py file.


It teaches about Static Media Server. Is this something that is still current?

From my understanding of the Official Django Tutorial and the Documentation, we can just use static files as seen here - https://docs.djangoproject.com/en/1.6/howto/static-files/

Thanks!

Daniel Roseman

unread,
Oct 13, 2014, 8:57:32 AM10/13/14
to django...@googlegroups.com
Your question is not clear. The rest of that page (sections 4.2 and 4.3) has just been explaining how you use static files, ie doing the same as the documentation you link to. The part you quote moves on from there, to talk about *user-uploaded* files. What is confusing you here?
--
DR.

Max Nathaniel Ho

unread,
Oct 13, 2014, 9:13:15 AM10/13/14
to django...@googlegroups.com
Hi DR,

Thanks for your reply.

I wanted to clarify -

1. The purpose of Static Media Server and
2. If it is an outdated concept

Andreas Kuhne

unread,
Oct 13, 2014, 9:32:33 AM10/13/14
to django...@googlegroups.com
Using a static media server or not is more a choice. I don't think it is an outdated concept, rather the opposite, depending on how you want to deploy it. We are using Amazon CloudFront for our media and static files. That way we don't get the load on our nginx servers (we generate alot of pictures on our site). Also even modern browsers have a limit on the number of files that they can download from the same URL at one time. By spreading the load on several servers, your webpage should load faster (as long as the static servers are fast, which they are on CloudFront).

Regards,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ba99d69-04bb-4b0e-b2f2-c5827a2c8b6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Collin Anderson

unread,
Oct 13, 2014, 2:04:49 PM10/13/14
to django...@googlegroups.com
Hi Max,

By default, the runserver command in a new django project will serve static media, which I think is what the tutorial is referencing.

It's useful for developing your website, but be sure to read the tutorial's warning:
While using the Django development server to serve your static media files is fine for a development environment, it’s highly unsuitable for a production - or live - environment. The official Django documentation on Deployment provides further information about deploying static files in a production environment.

Collin
 

Carl Meyer

unread,
Oct 13, 2014, 5:11:37 PM10/13/14
to django...@googlegroups.com
Hi Max,

On 10/13/2014 01:39 AM, Max Nathaniel Ho wrote:
> Hi all,
>
> I am going through this tutorial on Tango with Django
> - http://www.tangowithdjango.com/book/chapters/templates_static.html
>
> I extracted the specific part of the tutorial as seen in *BOLD*.
>
>
> *4.4. The Static Media
> Server<http://www.tangowithdjango.com/book/chapters/templates_static.html#the-static-media-server>*
>
> *Now that you can dispatch static files, let’s look at uploading media.
> Many websites provide their users with the ability to do this - for
> example, to upload a profile image. This section shows you how to add a
> simple development media server to your Django project. The development
> media server can be used in conjunction with file uploading forms which
> we will touch upon in Chapter 8
> <http://www.tangowithdjango.com/book/chapters/login.html#login-label>.*
>
> *So, how do we go about setting up a development media server? The first
> step is to create another new directory called media within our Django
> project’s root (e.g.<workspace>/tango_with_django_project/). The
> new media directory should now be sitting alongside
> your templates and static directories. After you create the directory,
> you must then modify your Django project’s urls.py file, located in the
> project configuration directory
> (e.g.<workspace>/tango_with_django_project/tango_with_django_project/).
> Add the following code to the urls.py file.*

I think that tutorial is confusing things by calling it a "Static Media
Server".

In Django terminology, "static assets" and "media" are two very
different things. "Static assets" are assets that are required for your
site to function (part of its code) and should be checked into your
version control. An example might be your site's logo.

Media, on the other hand, are part of your site's data, not it's code.
They are generally uploaded by users of your site, and you would back
them up periodically (along with your database contents), but not check
them into your codebase. An example might be user avatar images.

> It teaches about Static Media Server. Is this something that is still
> current?

Yes, if your site will have uploaded media, it is still necessary to
configure your local development server to serve them (and a standalone
web server, or a service like S3 or a CDN, to serve them in production).
The instructions given in that tutorial look correct. Here are the
related Django docs:
https://docs.djangoproject.com/en/1.7/ref/views/#serving-files-in-development

> From my understanding of the Official Django Tutorial and the
> Documentation, we can just use static files as seen here
> - https://docs.djangoproject.com/en/1.6/howto/static-files/

The staticfiles contrib app is only for handling static assets, not
uploaded media.

Carl

Max Nathaniel Ho

unread,
Oct 14, 2014, 8:47:47 AM10/14/14
to django...@googlegroups.com
Hi Carl, Colin and Andréas,

Thank you for all your replies.

You have more than answered my question and clarified my doubts :)
Reply all
Reply to author
Forward
0 new messages