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

  • Home
  • SEARCH
  • 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 8293641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:53:52+00:00 2026-06-08T13:53:52+00:00

I want to create a localhost-only API in Django and I’m trying to find

  • 0

I want to create a localhost-only API in Django and I’m trying to find a way to restrict the access to a view only from the server itself (localhost)? I’ve tried using:

  • ‘HTTP_HOST’,
  • ‘HTTP_X_FORWARDED_FOR’,
  • ‘REMOTE_ADDR’,
  • ‘SERVER_ADDR’

but with no luck.

Is there any other way?

  • 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-06-08T13:53:54+00:00Added an answer on June 8, 2026 at 1:53 pm

    The problem is a bit more complex than just checking a variable. To identify the client IP address, you’ll need

    request.META['REMOTE_ADDR'] -- The IP address of the client.
    

    and then to compare it with the request.get_host(). But you might take into account that the server might be started on 0.0.0.0:80, so then you’ll probably need to do:

    import socket
    socket.gethostbyaddr(request.META['REMOTE_ADDR'])
    

    and to compare this with let’s say

    socket.gethostbyaddr("127.0.0.1")
    

    But you’ll need to process lots of edge-cases with these headers and values.

    A much simpler approach could be to have a reverse proxy in front of your app, that sends let’s say some custom_header like X_SOURCE=internet. Then you can setup the traffic from internet to goes through the proxy, while the local traffic(in your local network) to go directly to the web server. So then if you want to have access to a specific view only from your local network, just check this header:

    if 'X_SOURCE' in request.META:
        # request is coming from internet, and not local network....
    else:
        # presumably we have a local request...
    

    But again – this is the ‘firewall approach’, and it will require a some more setup, and to be sure that there is no possible access to the app from outside, that doesn’t go through the reverse proxy..

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

Sidebar

Related Questions

i want create multiple search where statement $where_search is a multiple condition from post
i want create a custom json data from the mssql 2008 results so that
I want create module which update list of usb devices automatically (not only mass
I want to create a Silverlight app to extract and manipulate data from an
I'm trying to send e-mails from my localhost, using my gmail account, I've looked
I am trying to create a client/server by C, this is my first C
I want to use SQL Server to send email and found two possible way
I am trying to create a pool of channels/connections to a queue server and
I want create wordpress website into which I want create user management... That means
I want create an application with animate button? how can i do? after click

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.