Django Redis Cache Admin Interface - python

I implemented Redis Caching in my Django.. However, is there a Friendly User Interface to just check the cache values. Something like you can see all the cache keys and its values in Django Admin

You can check the status of your Redis Cache with the help of this github library,
https://github.com/erussell/django-redis-status
It is only accessible in the django-admin page.
By the way, you can always check your redis database using redis-cli.
I don't know whether I am getting your question in the correct way or not.
But this may help.

Related

Can I use an external database table for the login process in Django?

So I'm starting a new Django project that essentially requires the login & registration process be routed through an EXTERNAL & ALREADY created database.
Is it possible to have the User model use an EXTERNAL database table ONLY when Django is:
Logging in a user, to check if the login is valid
Registering a user, inserting data for that user in the external database
I would like for the rest of the Django server to use a local database.
If so, could someone either provide examples or guide me to documentation on the subject?
Easiest way to use multiple database with Django is to use a database routing. By default Django stick to single database, however, if you want to implement more interesting database routing system, you can define and install your own database routers.
Database routers are installed using the DATABASE_ROUTERS setting. You have to specify this setting in your settings.py file
What you have to do is write one AuthRouter as described Django documentation Django Multiple Database
"Yes, but"
What you are looking for in the docs is called "database router".
There is even an example for the auth app in the docs there.
But, there is s serious drawback to consider with this approach:
We cannot have cross-database relationships in the models. If auth tables are in a separate database, this means that any otehr app that needs a foreign key to User model is going to run into problems. You might be able to "fake" the relationships using a db that doesn't enforce relationship checks (SQLite or MyISAM/MySQL).
Out of the box, such apps are: session, authtoken, and admin (and probably more).
Alternatively, a single-sign-on solution might do a better job: django-sso, or django-mama-cas + django-cas-ng, or the commercial Stormpath.

Django's authentication backends change

I have to change the Django's authentication backend (the default is django.contrib.auth.AuthenticationBackend) to one of my own. The problem is that since Django stores the authentication backend for a requested user in the session, it throws errors to me when I try to use the new backend. The option is to delete all the session information. Is there a better way to do this? Or else, what is the most preferred way?
Look at the Pinax project's account auth_backends , there it replaces with own one. I think Pinax code helps you while changing Django's authentication backend.

Authenticate users across Django projects - where to begin?

I'm in the process of building several Django based web applications for the same client. What I would like to do is set up an authentication server so that user credentials can be shared among django projects e.g. Jan Doe creates account for App-A and can use the same un and pw to log in to App-B.
Django packages is only somewhat helpful as I can't tell from the package descriptions if the package will help me do what I want to do or not.
I'm very inexperienced in this area so I don't even know if my questions are appropriate, but here goes:
Should I even be looking at django packages?
Would looking for a python based auth server be more appropriate?
Where should I start to solve this problem?
No, you don't need a separate package. Just use Django's built-in multi-database handling. Check out: https://docs.djangoproject.com/en/dev/topics/db/multi-db/.
Essentially, you designate one of your databases as the one that's going to store the user data and make sure that database is added to each of your other projects. Then set up a router that checks for app_label=='auth' and route to the "user" database for those instances. There's an example in the docs.

Best practice: How to persist simple data without a database in django?

I'm building a website that doesn't require a database because a REST API "is the database". (Except you don't want to be putting site-specific things in there, since the API is used by mostly mobile clients)
However there's a few things that normally would be put in a database, for example the "jobs" page. You have master list view, and the detail views for each job, and it should be easy to add new job entries. (not necessarily via a CMS, but that would be awesome)
e.g. example.com/careers/ and example.com/careers/77/
I could just hardcode this stuff in templates, but that's no DRY- you have to update the master template and the detail template every time.
What do you guys think? Maybe a YAML file? Or any better ideas?
Thx
Why not still keep it in a database? Your remote REST store is all well and funky, but if you've got local data, there's nothing (unless there's spec saying so) to stop you storing some stuff in a local db. Doesn't have to be anything v glamorous - could be sqlite, or you could have some fun with redis, etc.
You could use the Memcachedb via the Django cache interface.
For example:
Set the cache backend as memcached in your django settings, but install/use memcachedb instead.
Django can't tell the difference between the two because the provide the same interface (at least last time I checked).
Memcachedb is persistent, safe for multithreaded django servers, and won't lose data during server restarts, but it's just a key value store. not a complete database.
Some alternatives built into the Python library are listed in the Data Persistence chapter of the documentation. Still another is JSON.

How do I keep state between requests in AppEngine (Python)?

I'm writing a simple app with AppEngine, using Python. After a successful insert by a user and redirect, I'd like to display a flash confirmation message on the next page.
What's the best way to keep state between one request and the next? Or is this not possible because AppEngine is distributed? I guess, the underlying question is whether AppEngine provides a persistent session object.
Thanks
Hannes
No session support is included in App Engine itself, but you can add your own session support.
GAE Utilities is one library made specifically for this; a more heavyweight alternative is to use django sessions through App Engine Patch.
The ways to reliable keep state between requests are memcache, the datastore or through the user (cookies or post/get).
You can use the runtime cache too, but this is very unreliable as you don't know if a request will end up in the same runtime or the runtime can drop it's entire cache if it feels like it.
I really wouldn't use the runtime cache except for very specific situations, for example I use it to cache the serialization of objects to json as that is pretty slow and if the caching is gone I can regenerate the result easily.

Categories

Resources