It spent me several hours to find out the root cause why the importing operation failed while importing ‘a.b.c’ module. I wrote a function in init.py in ‘a’ package, I plan to get current module path use: self.cur_dir = __path__.pop() In later logic, if I tried to load some module under this ‘a’ package, it always failed with below error: ImportError: No module named b.c But it is fine when I try to load it via python shell or by other ways.

Read More…

If we want to create django project with uwsgi, it is convenient to let uwsgi workers auto reload if there are some changes happens. Basically, we just need monitor the changes of *.py files in the project dir. For apache+mod_wsgi development environment, there is a monitor.py which called in wsgi.py can achieve the same target, but it looks like this method doesn’t works well in nginx+uwsgi development, e,g: graceful reload of uwsgi workers could be affected when WSGI application executes monitor.

Read More…

By default, when use Django admin to upload a file/image in inline models, the url it got is: === <p class="file-upload"> Currently: <a href="/upload/ct_attachment/2014/09/18/cloud_SL4WKba.jpg">ct_attachment/2014/09/18/cloud_SL4WKba.jpg</a> Change: <input id="id_attachments-0-files" type="file" name="attachments-0-files"/> </p> When one click the URL to download the file already uploaded, it will open in the same window, which means the admin UI will be replaced with the file downloading window. Sometimes, we just need to check what’s the file it is, so open it in a new windows is much better.

Read More…