1
class FileUploadModel(models.Model):
    title = models.CharField(max_length=50)
    uploaded_file = models.FileField(upload_to = 'bose')

Error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 231, in execute
    self.validate()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 30, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 158, in get_app_errors
    self._populate()
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 88, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/bose/DJANGO/blog/blog/models.py", line 22
    uploaded_file = models.FileField(upload_to = 'bose')

IndentationError: unindent does not match any outer indentation level

Where am I going wrong?

sbose
  • 1,791
  • 5
  • 24
  • 46
  • Need a bit more context code .. are you showing lines 10+ from manage.py? can you show some of the surrounding code, especially preceding the 3 lines you showed .. tricky to know otherwise what's going on. You've checked for tab vs blanks, right? – Levon Apr 26 '12 at 21:31
  • Yeah ive checked. Removing the uploaded_file = models.FileField(upload_to = 'bose') causes the error to vanish! so that line must be the problem child – sbose Apr 26 '12 at 21:34
  • 2
    tabs are evil, never mix tabs and spaces, convert tabs to 4 spaces http://www.python.org/dev/peps/pep-0008/#tabs-or-spaces – Anurag Uniyal Apr 26 '12 at 21:41

2 Answers2

9

Well, if you copied your code directly into the edit box, then your problem is that you have a mix of tabs and spaces. The title line in your question source is preceded by a tab character, while the following line is preceded by four spaces.

See this question and its answers for more information. You can use the -t option if you want Python to warn you when you're using a mix of tabs and spaces.

Community
  • 1
  • 1
senderle
  • 145,869
  • 36
  • 209
  • 233
  • just curious what editor did you paste this in? emacs must convert everything into spaces .. I see no tabs – Levon Apr 26 '12 at 21:34
  • I looked directly in the edit box. I'm not sure how stackoverflow works, but from the look of things, it converts tabs in source to spaces in rendered text, using a tabstop of 8. – senderle Apr 26 '12 at 21:36
  • Thanks .. that's a great way to do this (didn't think of it). I too see the tab there. – Levon Apr 26 '12 at 21:38
  • thanks, problem solved! But I still didn't understand how you figured out that those were spaces :D – sbose Apr 26 '12 at 21:41
  • @SHOUBHIK BOSE, I just clicked on the edit link. Try it -- put the cursor at the beginning of the `title` line, press the right arrow, and you'll see that on the fifth press, the cursor will jump by four spaces. – senderle Apr 26 '12 at 21:43
  • @senderle After trying to upload a record from the admin panel, I'm getting this : table blog_fileuploadmodel has no column named uploaded_file – sbose Apr 26 '12 at 21:49
  • @SHOUBHIK BOSE, did you remember to put the line back? – senderle Apr 26 '12 at 21:50
  • Yeah, the field shows up in the Admin panel's autogenerated form – sbose Apr 26 '12 at 21:54
  • @SHOUBHIKBOSE, hm, well that's beyond me. I'm not much of a django person, unfortunately. I just know a bit about tabs and spaces :) You may have to ask a new question. – senderle Apr 26 '12 at 21:56
  • hey No probs. That was a stale database table that caused the issue. Created a new model. That worked :) – sbose Apr 26 '12 at 22:00
0

If you use Komodo editor you can do as it suggests in one of similar error messages:

1) select all, e.g. Ctrl + A

2) Go to Code -> Untabify Region

3) Double check your indenting is still correct, save and rerun your program.

I'm using Python 3.4.2

Imtiaz Pabel
  • 5,307
  • 1
  • 19
  • 24