Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3750568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T08:57:07+00:00 2026-05-19T08:57:07+00:00

I was trying to retrieve the file path using python __file__ variable under django

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T08:57:08+00:00Added an answer on May 19, 2026 at 8:57 am

    To get a current directory path you can do something like this.

        import os  
        os.path.abspath(os.path.dirname(__file__))
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve a jrxml file in a relative path using the
I am trying to retrieve a JSON file from a web service using the
I'm trying to retrieve the current path of a file from a project in
I am trying to retrieve JSON data from an external text file using a
I'm trying to retrieve a file from a server using SFTP (as opposed to
I'm trying to retrieve N number of items from an XML file using simpleXML
I am trying to retrieve DataTable from .xls file. Below are my code: OleDbConnection
I'm trying to retrieve folders name from a zip file. I wrote this simple
I'm trying to save a huge NSArray to a file and then retrieve it...
I'm trying to retrieve this page using Apache HttpClient: http://quick-dish.tablespoon.com/ Unfortunately, when I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.