Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#20400 closed Uncategorized (invalid)

during tutorial02 os, BASE_DIR not defined

Reported by: karim.nassar@… Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you follow the instructions in the tutorial02: https://docs.djangoproject.com/en/dev/intro/tutorial02/#customizing-your-project-s-templates

You get error:

  File "/home/myUser/path/to/project/projectName/projectName/settings.py", line 116, in <module>
    os.path.join(BASE_DIR, 'templates')
  NameError: name 'os' is not defined

You need to add this line:

  import os

Then you get this error:

  File "/home/myUser/path/to/project/projectName/projectName/settings.py", line 116, in <module>
    os.path.join(BASE_DIR, 'templates')
  NameError: name 'BASE_DIR' is not defined

Add this line to settings.py:

   BASE_DIR = os.path.dirname(os.path.abspath(__file__))

Maybe that needs to be in tutorial?

Change History (7)

comment:1 by Tim Graham, 11 years ago

Resolution: invalid
Status: newclosed

You are likely using the development version of the tutorial (notice "dev" in the url) with Django 1.5 instead of the development version of Django.

comment:2 by anonymous, 11 years ago

This really should be in the tutorial.

comment:3 by anonymous, 11 years ago

Thanks a lot!

comment:4 by rando305@…, 10 years ago

I recently had this same problem. It would be nice to update this Tutorial. However - I am very pleased with the Tutorial and Django. I'm looking forward to writing code again.

After doing this - I still get an error file is not defined. Any help would be appreciated.

comment:5 by Tim Graham, 10 years ago

As noted above, if you have this problem, you aren't using the correct version of the tutorial for the version of Django you have installed.

Please see SupportChannels for getting help. This ticket tracker is not the place to get help.

comment:6 by ShawnMTherrien, 10 years ago

Version: 1.51.6

I'm using v1.6 and the following url:
http://django.readthedocs.org/en/1.6.x/intro/tutorial02.html

I'm not using "dev" and the "import os" and setting BASE_DIR is still not explained.

Love the docs, but things like this detract from the lessons that the tutorial is actually trying to teach.

in reply to:  6 comment:7 by Sasha Romijn, 10 years ago

Replying to ShawnMTherrien:

I'm not using "dev" and the "import os" and setting BASE_DIR is still not explained.

Yes, this is true. However, this will not lead to the error you describe. The context of this in the tutorial is that you add the lines to the settings file. In Django 1.6, the standard settings already import os and define BASE_DIR.

Note: See TracTickets for help on using tickets.
Back to Top