I was trying to retrieve the file path using python __file__ variable under django though i am getting correct path. It’s behavior is little weird. Here is my attached sample code please let me know why is the behavior so.
from django.shortcuts import render_to_response
import datetime
class WebServer():
def __init__(self):
pass
def display_first_page(self, request):
print "File Path: ", __file__
return render_to_response('Hello')
I have stored this code at the given location : C:\Django_example\MySample. Ideally it should have returned something like C:\Django_example\MySample\webserver.py, but instead i am getting C:\Django_example\MySample\..\MySample\webserver.py . Can someone please point me to the right direction.
Thanks in advance,
Rupesh
To get a current directory path you can do something like this.
This will return a normalized absolutized version of the pathname(absolute path) as well as it will normalizes the path. For example, on Unix and Mac OS X systems the path /var/www/project will work fine, but on Windows systems that is not a good path. Normalizing the path will convert forward slashes to backward slashes. Normalization also collapses redundant separators, for example the path A/foo/../B will be normalized to A/B.
Rupesh