If you are reading Writing your first Django app, part 6, the code won’t work until you put in the following code from https://docs.djangoproject.com/en/1.8/howto/static-files/ (in the section named Serving static files during development) to the urls.py file.
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Basically your urls.py needs to know where to route the static file requests. =)
It took me a while to figure out how to do this correctly. There is too much noise from google search… Here are my settings for everything to display correctly in my admin site w/ Django 1.8.
USE_TZ = True
TIME_ZONE = 'US/Pacific'
HUMAN_TIME_FMT = '%Y-%m-%d %H:%M:%S %p'
HUMAN_TIME_FMT is optional, I put it there for my own usage.
from django.conf import settings
from django.db import models
from django.utils import timezone
sync_start = models.DateTimeField('sync starts')
sync_end = models.DateTimeField('sync ends')
fmt = settings.HUMAN_TIME_FMT
my_dt1 = timezone.localtime(self.sync_start).strftime(fmt)
my_dt2 = timezone.localtime(self.sync_end).strftime(fmt)
return 'From ' + my_dt1 + ' => ' + my_dt2
More to read:
Here is my little side project to convert excel files to json objects. I mainly used the Google App Engine and the Python xlrd module.
Feel free to try it out at http://excel2json.appspot.com/.
curl -F f=@my_file.xls http://excel2json.appspot.com/2json
All you need is just one line of code!
The libraries needed are: xlutils, xlrd and xlwt. They are all under the package called xlutils. So just issue the following command.
sudo pip install xlutils
localhost:~ birdchan$ python
Python 2.7.2 (default, Jun 16 2012, 12:38:40)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlutils
Should have no error messages.
I installed MySQL-Python (version 1.2.3 at the time being) from http://sourceforge.net/projects/mysql-python/ on my osx 10.6, python version 2.6.1. Just do the usual “python setup.py build” and “python setup.py install”. However though, in the python cli, when I do “import MySQLdb”, I got some error.
>>> import MySQLdb
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/birdchan/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/birdchan/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: image not found
Obviously, the error is “Library not loaded: libmysqlclient.18.dylib”. A quick fix is to simply create a symlink.
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
I suppose you can also play with your env path.
Just found this handy online tool to try out regular expressions. It helps when you want to focus on the regular expression more than your python code.