Home » Odeon Blogs »

Pyro

Locale error in manage.py createsuperuser

Recently, when I run python manage.py createsuperuser, I run into this problem

  1. return getpass.getuser().decode(locale.getdefaultlocale()[1])
  2. TypeError: decode() argument 1 must be string, not None

Frustrated, I traced back why this is happening. It turns out that Python cannot detect default locale in my system. Therefore, locale.getdefaultlocale() is returning None and hence, causing the error.  The solution is to set some locale variables in my environment.

  1. export LANG=en_US.UTF-8
  2. export LC_ALL=en_US.UTF-8

Now, createsuperuser command runs successfully.


Categories: Django locale


Tagged as: django locale

2 Comments

Vim : Working with multiple split windows

One of the features that I can't live without in Vim is the "Split-screens".  For starters, the command :sp or :split will split the Vim window horizontally. And :vsp or :vsplit will split it vertically. It's common to supply a filename in the command. Imagine coding an HTML file in one split view and the respective CSS in the other all just in one window.

Navigating between split

Arbitrarily, you can have any number of split-screens in one window or tab. And navigating between them is pretty easy in Vim. Ctrl-W w will switch between split-screens and Ctrl-W j ( h or k or l ) will to navigate through split-screens in respective directions. For easier manipulation, I slap this in my .vimrc remapping Ctrl-W with just Ctrl for basic movements between buffers.
  1. nmap <C-j> <C-w>j
  2. nmap <C-k> <C-w>k
  3. nmap <C-h> <C-w>h
  4. nmap <C-l> <C-w>l

Changing the default behavior

By default, vim will open the new vertical split window to the left of the old one and the new horizontal split windows will appear on the top of the old one. If you prefer otherwise,
  1. set splitbelow
  2. set splitright

Swapping Split Windows

While working with multiple split windows, I often find myself running into situations where I want to swap the positions of the two split windows. This can be done in with a combination of Ctrl-W with basic movement commands. For instance,  Ctrl-W r will rotate the split windows.  However, most of the time, I would end up screwing up the existing layout while rearranging the positions of the split windows. Looking for a better solution, I stumbled across a neat little solution
  1. function! MarkWindowSwap()
  2. let g:markedWinNum = winnr()
  3. endfunction

  4. function! DoWindowSwap()
  5. let curNum = winnr() "Mark destination
  6. let curBuf = bufnr( "%" )
  7. exe g:markedWinNum . "wincmd w"
  8. let markedBuf = bufnr( "%" ) "Switch to source and shuffle dest->source
  9. exe 'hide buf' curBuf "Hide and open so that we aren't prompted and keep history
  10. exe curNum . "wincmd w" "Switch to dest and shuffle source->dest
  11. exe 'hide buf' markedBuf "Hide and open so that we aren't prompted and keep history
  12. endfunction

  13. nmap <silent> <leader>mw :call MarkWindowSwap()<CR>
  14. nmap <silent> <leader>pw :call DoWindowSwap()<CR>

<leader> represents the leader key which by default is \ or whatever key that you have assigned to.

Move to the position of the split window and mark it with <leader>mw and move the the destination window position and press <leader>pw . Hola! you will have swapped buffers without screwing up the existing window layout.
Neat, isn't it?!

For more information on split windows, press :help window. Have fun, coding!


Categories: productivity vim


Tagged as: productivity vim

Leave a Comment
Page generated in: 0.15s