Opened 2 years ago

Closed 2 years ago

Last modified 12 months 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 Changed 2 years ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 2 years ago by anonymous

This really should be in the tutorial.

comment:3 Changed 21 months ago by anonymous

Thanks a lot!

comment:4 Changed 19 months ago by rando305@…

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 Changed 19 months ago by timo

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 follow-up: Changed 13 months ago by ShawnMTherrien

  • Version changed from 1.5 to 1.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.

comment:7 in reply to: ↑ 6 Changed 12 months ago by erikr

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