When we work with Django in local environment, we change the structure of the Data Base using Command Prompt through migration.
But for using Django in server, i don't now how can i apply such changes? How can i type commands to change Data Base structure? Is it a good way to upload site files every time that i do some change again.
The whole point of migrations is that you run them on both your local database and in production, to keep them in sync.
Related
Is there a way to run a python script that will add data to this SQLite DB then? I mean, a completely separate .py file that I will run in the shell, doing python thefile.py in an SSH connection?
Of course, this file will be on the same server as the whole Django project.
This way, I can easily access the data from the DB from my Django project, and display it the way I want in a pretty HTML/CSS web page.
Thanks
Is there a reason for not using django? you can add a command to the manage.py the way it's described here https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/
I have a Django application that integrates data from a SQL database and displays that as a downloadable HTML table. Now I would also like to add analysis functionality, but instead of painstakingly adding only a few functionalities using JavaScript, I want to redirect the user to a Jupyter notebook, so the user has full access to the functionality of Python data analysis libraries or even other languages. Now I'm not sure how to approach this and I have several questions:
Am I right that Jupyter needs to be run on a different server than the Django app since it uses the Tornado server?
How would I transfer the data produced with Django to Jupyter? I store the data in a new MySQL table, but I would at least need to transfer the table name.
Given the table name was transferred to Jupyter I would still need to execute custom code to access the database. I found in this question that some defaults for code execution can be set in IPython configuration, but since the table from which the data should be loaded is never the same, this would have to be adapted dynamically.
I'm glad for any suggestions and comments on whether this idea makes sense at all.
Am I right that Jupyter needs to be run on a different server than the Django app since it uses the Tornado server?
No. They can run on the same server.
How would I transfer the data produced with Django to Jupyter? I store the data in a new MySQL table, but I would at least need to transfer the table name.
You can run django and Jupyter together and execute any django code from Jupyter. The easiest way to do so is by using shell_plus from the package django-extensions You can even connect to the production database.
You should consider the possible security and data safety risks. This is a potential vector for remote code execution and data leaks.
It's probably safer to spin up a cloned django instance with a cloned database or use a different django configuration (settings.py) with read-only access to the db.
It's quite easy to mess up production data from Jupyter, since you can do stuff such as User.objects.all().delete() And that would be a problem...
Also consider running this as a user with stricter read and write permissions than you use for your regular django app.
And of course, you should make sure that the Jupyter site is not exposed on a publicly accessible url.
I have a development Django project using MySQL, and it is deployed at PythonAnywhere. I am able to push my code updates via GIT, and the Django migrations take care of the database STRUCTURE but my question is about data.
During development I may add a new capability that relies on master data which I enter in the DEV database as I develop and test. When deploying I'd like to copy over the master data to the new database rather than re-enter it all.
Is exporting and importing files the best way or is there a more professional way?
I think the simplest way to do this is by using the dumpdata management command.
The output for this command can be used in executing the loaddata management command.
I have a Django application that runs on apache server and uses Sqlite3 db. I want to access this database remotely using a python script that first ssh to the machine and then access the database.
After a lot of search I understand that we cannot access sqlite db remotely. I don't want to download the db folder using ftp and perform the function, instead I want to access it remotely.
What could be the other possible ways to do this? I don't want to change the database, but am looking for alternate ways to achieve the connection.
Leaving aside the question of whether it is sensible to run a production Django installation against sqlite (it really isn't), you seem to have forgotten that, well, you are actually running Django. That means that Django can be the main interface to your data; and therefore you should write code in Django that enables this.
Luckily, there exists the Django REST Framework that allows you to simply expose your data via HTTP interfaces like GET and POST. That would be a much better solution than accessing it via ssh.
Sqlite needs to access the provided file. So this is more of a filesystem question rather than a python one. You have to find a way for sqlite and python to access the remote directory, be it sftp, sshfs, ftp or whatever. It entirely depends on your remote and local OS. Preferably mount the remote subdirectory on your local filesystem.
You would not need to make a copy of it although if the file is large you might want to consider that option too.
I have a Django 1.6 project (stored in a Bitbucket Git repo) that I wish to host on a VPS.
The idea is that when someone purchases a copy of the software I have written, I can type in a few simple commands that will take a designated copy of the code from Git, create a new instance of the project with its own subdomain (e.g. <customer_name>.example.com), and create a new Postgres database (on the same server).
I should hopefully be able to create and remove these 'instances' easily.
What's the best way of doing this?
I've looked into writing scripts using some sort of combination of Supervisor/Gnunicorn/Nginx/Fabric etc. Other options could be something more serious like using Docker or Vagrant. I've also looked into various PaaS options too.
Thanks in advance.
(EDIT: I have looked at the following services/things: Dokku (can't use Heroku due to data constraints), Vagrant (inc Puppet), Docker, Fabfile, Deis, Cherokee, Flynn (under dev))
If I was doing it (and I did a similar thing with a PHP application I inherited), I'd have a fabric command that allows me to provision a new instance.
This could be broken up into the requisite steps (check-out code, create database, syncdb/migrate, create DNS entry, start web server).
I'd probably do something sane like use the DNS entry as the database name: or at least use a reversible function to do that.
You could then string these together to easily create a new instance.
You will also need a way to tell the newly created instance which database and domain name they needed to use. You could have the provisioning script write some data to a file in the checked out repository that is then used by Django in it's initialisation phase.