Comments (6)
I can understand the reasoning. However I think in this case you should provide a way to configure a function that returns the IP address.
from django-user-sessions.
There is already a way to provide the correct IP address. For example I use the following middleware on heroku:
class SetRemoteAddrFromForwardedFor(object):
def process_request(self, request):
try:
real_ip = request.META['HTTP_X_FORWARDED_FOR']
except KeyError:
pass
else:
# HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
# Take just the first one.
real_ip = real_ip.split(",")[0]
request.META['REMOTE_ADDR'] = real_ip
However it might be good to include such information in the documentation.
from django-user-sessions.
I'm using something similar. However this is IMO not how configuration management should be working. IMO the function to get the IP should be configurable, receive a request object, and return an IP.
from django-user-sessions.
@snoepkast thanks for the information, the snippet should indeed be updated. This is also a great example on why this package doesn't consider X-Forwarded-For headers. Every platform is different and this particular header is implementation specific.
from django-user-sessions.
Hi @davidhalter. It might work for your situation, but not in general. Please refer to the explanation given in #12, #34 and #35 on why that is a bad idea.
from django-user-sessions.
I came here looking for this exact solution. Your middleware code looks good and I will implement it. However given the answer in this stack overflow, you might want to consider using the last ip address in x-forwarded-for instead of the first, at least on heroku.
from django-user-sessions.
Related Issues (20)
- Warnings about ugettext_lazy being deprecated
- This project is looking for maintainers! HOT 3
- Security issue with default URL suggestion HOT 2
- How would one go about measuring session length? HOT 1
- How to import the default Session ? HOT 1
- Bug: Opera browser is recognized as Chrome browser in template.
- Possibility of a new Release HOT 15
- Application does not works with Django 4.0 HOT 1
- django 4.0 support
- fails to build with django 4 HOT 2
- Slow UPDATE queries? HOT 2
- RuntimeError: Model class django.contrib.sessions.models.Session doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS HOT 5
- update readme links HOT 1
- It's no longer possible to properly detect the platform version, so we shouldn't try to HOT 3
- Not saving user_agent and ip even while using geoip
- Switch to using setuptools_scm HOT 1
- Utilize ruff
- Drop unsupported versions of Django
- Clean up some of the dev dependencies
- Handling session cookie delete on logout
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-user-sessions.