I have a django app that works with .csv files as database, in these files i have the users of the system (i can't change that), i need to implement security (a login) in the site. Any idea?
Your question is very vague and you didn't ask for specifics so here is a general overview of what you'll need to do.
If you intend to use django's built-in authentication system then you'll have to setup a database; even if its sqlite. Once you have setup a database, run manage.py syncdb to create the necessary authentication tables (by default, the settings.py that django creates is already setup for the authentication system, so you don't have to make any other changes).
Once you have that done, you'll have to write a fixture to load the users from the csv file into the authentication tables. You can read up on that in the documentation under providing initial data for models.
Now you are ready to set passwords and permissions. Your next task will be to make sure that the csv file is in sync with the authentication tables if there a change in the csv file.
Related
I built a Django project with a few models. Now I created a second server with the same setup. This one is meant to be the deployment server. Databases are separate from the dev-server.
However can you tell me if I can simply copy the databases from the dev server to the deploy or will the Django logic, since I also mean the user models and permissions etc.
The tables which I created myself are no problem to transfer to the new server. However I am wondering If Django gets confused when I also transfer something like the auth_user Model.
Should this work since I also just copied the backend logic as well?
I already have an existing website running and want to transfer just the users (usernames, passwords and emails) to another database for a separate Django website as I am rebuilding it.
You can configure both databases in your django configuration file. select the user data from one database and then put the records in the other.
Multiple Databases in Django.
Moving an object from one database to another
I set up a simple django site using django-allauth.
I created some oauth providers in the database.
Everything is fine and working on my laptop now.
I would like to store the created database tables somehow.
Use case: I want to set up a new development environments on a different PC painlessly.
How to store the initial data of django_allauth, so that after checking out the app from git the command manage.py migrate is all I need to have the relevant database tables filled?
Django_allauth already save those data to the database, you will find them in a table *_SocialApp, here is the model code from django_auth source
I have a django application that uses a postgres DB.
I have a chef recipe that sets up the postgres DB, including setting up a postgres username/password for the django app to use.
This username/password is then used by the DATABASES settings.py value.
At the moment I have to have the postgres details in both attributes.rb and in settings.py.
How can I have them in just one place?
Options I have currently considered:
Having settings.py (or part of it) generated by a chef template. That way the details only need to be in the chef recipe.
The downside of this is that the django app is incomplete unless it is deployed via chef. (This might not be that much of an issue, as even local dev is done with vagrant+chef).
Having a known file on the filesystem that settings.py checks and loads some values from. This file is generated by chef.
This is only a little bit better than the first solution. Also it requires some boilerplate code in settings.py to load and parse the file.
Have the details in settings.py and let chef extract them (somehow).
This approach is problematic because it muddles with the ordering in the chef recipe (I have to check out my django app, extract the value, use the values to set up postgres, and then start django).
That itself might not be too bad, but the real issue comes when/if I want to move to a system where passwords aren't in source-controlled files but in something like chef's data-bags.
I've googled quite a bit, but other than various discussions on the layout of settings.py and general talk about how to use django and chef, I can't find a nice solution.
Surely someone else has deployed a django app with postgres using chef and come across this before?
You should use a data bag. And as you store a password there, it should be encrypted data bag. Then you can read data from it in both recipes (postgres and python).
And storing your passwords in attributes also is not a good idea - because they are too exposed.
What would be the best solution to use a different authentication backend for the Django admin site?
See the documentation, which contains this quote:
The Django admin system is tightly
coupled to the Django User object
described at the beginning of this
document. For now, the best way to
deal with this is to create a Django
User object for each user that exists
for your backend (e.g., in your LDAP
directory, your external SQL database,
etc.) You can either write a script to
do this in advance, or your
authenticate method can do it the
first time a user logs in.