Table Of Contents
- Environment Setup & Requirements
- Setup Webpack
- First Webpack Packaged Assets
I’ll assume that you already know Django and is already well versed with it and you just want to integrate Webpack into your project. If you already know what is Webpack and how it works please proceed to Environment Setup & Requirements. For those of you that is not quite sure what Webpack will bring into your Django project then please read on for brief introductory of it. Continue reading
By default Django development server will only be accessible through the local machine(127.0.0.1). If you want to access the server remotely then you need to run the the development server with your IP as an argument:
python manage.py runserver [your-ip-here]:8000
Change the “[your-ip-here]” to your actual IP. If you IP address is 18.104.22.168 then you will need to run the server using this:
python manage.py runserver 22.214.171.124:8000
If you have multiple network configured or you want the server to be automatically available on what your IP now currently is. Then enter 0.0.0.0 as your IP, like this:
python manage.py runserver 0.0.0.0:8000
This will bind the development server of Django on all available network/IP address. Then you will the see same message when you use just use python manage.py runserver upon successfully creating the server but instead of http://127.0.0.1:8000/ you will see a http://0.0.0.0:8000/, then you will now be able to access your server remotely.
0 errors found
February 01, 2014 - 10:13:18
Django version 1.5.1, using settings mysite.settings
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Warning: This server is only meant for development use so you must not use this as a production solution. This is also discouraged by Django team.
To make a Python Datetime timezone aware for Django Datetime field. You can use the utc from django.utils.timezone for replacing the tzinfo of Python Datetime but make sure that it is in UTC format. Below is a simple example of how to retrieve the current date and time and make it timezone aware for Django Datetime model field.
from django.db import models
from django.utils.timezone import utc
class Foo( models.Model ):
#datetime field sample
date_posted = models.DateTimeField( auto_now_add=True, blank=True )
def save(self, *args, **kwargs):
#the datetime generated by datetime module will now be timezone aware
self.last_date_updated = datetime.datetime.utcnow().replace(tzinfo=utc)
super(Foo, self).save(*args, **kwargs)
Ive upgraded the Django version Im using to 1.5 from 1.4.5 several days earlier and since then I was unable to run my app in release mode. Whenever I set DEBUG=False in settings.py a “HTTP Error 500” page is always served but setting it to DEBUG=True will make the app run fine.
Ive found out that now on version 1.5, Django has a new setting in settings.py:
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = 
This setting is not included in version 1.4 and is now needed in 1.5. You need to add your domain here ex: www.jamesbaltar.com. See this link for more
For every Django projects we have a settings.py that contains all the settings for a project but some of these must have an absolute path. So moving a Django project to another directory can be a pain. Luckily we have the os module. These module can and will help us make our projects easy to move.
Just add these line in your settings.py
APP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + "/"
Now for every settings that needs an absolute path just prepend the path with APP_PATH
#for static root
STATIC_ROOT = APP_PATH+static/
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Dont forget to use absolute paths, not relative paths.