Set up an existing Django app on another server - django

This must, must, must be a duplicate but I can't find the answer either here or on Google.
I have an existing Django app and I want to deploy it on another server.
What are the steps I need to go through to get it running elsewhere, in words of one syllable?
At a minimum, presumably:
create a project on the new server
copy over all my app's files into that project
edit localsettings.py or equivalent with local database settings etc
run python manage.py syncdb to create my database
load fixtures
run tests
Is that it? Are there any unofficial or official instructions for copying an app elsewhere?
Thanks.

The most basic, easy way to do it is:
Set up the server environment so that it matches the current environment as closely as possible. The most important thing is that you're using the same version of Django (obviously). You can run a different database, but it makes porting from the old server to the new server a little more involved. Otherwise, you will just have to adjust your settings to match the new server, if they can't be duplicated (ie, user names, etc).
Copy over your code
Dump your old database structure and data into the new database
Running startproject isn't strictly necessary. Your web server just needs to be configured correctly, to run django with the appropriate settings.py file -- and Django takes it from there.

Related

How do I prevent my Django Database from being overwritten

Currently I have a Django application running on my personal website from PythonAnywhere.com. When I make updates to the site I login to PythonAnywhere and git pull to update my application. When I do this the data that was entered through the website since the last update gets lost from the database when I update. What can I do to overcome this?
I am currently using the SqlLite version that comes preinstalled with the Django App. This likely could be part of the issue but need some help understanding how to overcome it.
I presume that your Django project is connecting to the SQLite database that gets generated when you create a new project and you are pushing that database in your deployment. That database won't be suitable for production and won't retain your changes, you instead need to setup a database that your application can connect to.
Here is some information on PythonAnywhere about databases:
https://help.pythonanywhere.com/pages/KindsOfDatabases/
And the Django documentation:
https://docs.djangoproject.com/en/4.0/ref/databases/

Do I have to run migrate in django if I don't need admin?

I'm building small website where I will display pages as static pages not from database.
Do I have to run migrate when starting a Django project if I don't need to use Django admin interface?
Yes, but...
Django has three common app which require to run migration at initial stage auth, contenttypes and session which provides all the basic functionalities of authentication, sessions, activity performed etc.
If you are not going to use any of those functionalities then you can run your app without migrations but it will only use your view and templates which is similar to host your html in any simple server without any configuration where you have no need of using such enrich framework like django
To make it short, migrate sets up the database by applying existing migrations in installed apps if it's not set already.
If your work doesn't use data storage then you can do without running migrate.
(But this step becomes necessary if you need to store data, and if you just want to serve some static content, you might just consider using a simple HTTP server, like Apache or Nginx).

How to have a site hosted on Heroku with database being stored locally on my computer?

I am hosting a Django site on the Heroku. However, Heroku does not allow databases with over 10 000 records stored for free. Can I store my database locally on a computer I have direct access to and still host the site on Heroku?
It is possible to use external database in Heroku by adding configuration:
heroku config:add DATABASE_URL=mysql://user:pass#server:port/database_name
But the question is what to I write for server in this case?
This is possible, but you will have to open up some ports on your local computer. Please look into port fowarding if you are into this. You are even able to post your whole website on your computer.
Personally I wouldn't recommend doing this, because you computer could become more vulnerable and you have to rely on your own home network and computer speed. Scaling is not easy with this setup.
However, there is (some kind of) an alternative. Django uses SQLite as the default database. You are able to use SQLite on Heroku. Please note that SQLite is not build for websites that interact a lot with your database and you cannot push a new build as easily as you would normally do. You will have to export the database first and then rebuild it later as Heroku creates a fresh website each time it builds (and the new database entries will be gone with that).
In other words: I would recommend to just pay for an upgrade of the database or move to another hosting company. I am sorry.

How to deploy django server into production environment without a full source code?

I am still a newbie to Python and Django. I am developing a application using Django which will eventually go to the production server. It's a customized web application for the client. After doing some research, I found out Apache with mod_wsgi is the best option for Django deployment. I just have to copy and paste the code into the production server and the application is accessible. But what if I don't want to give the whole source code and give only the executable application to the client(P.S client wants to deploy the application to their own server). Is something like this possible in Python/Django?
You could only give them the .pyc files corresponding to your source code files. That will make it slightly harder for them to look at your source code. However, it's a very limited measure (i.e. they can still recover some of the structure from your source code), and it's probably a bad idea.

Modifying existing Django site

I am completely new to this Django world. I haven't tried it ever before.
Now the problem is as below;
One of my clients was hosting his site somewhere else that I don't know and they built the site using Django. The host company doesn't allow to make any changes on their server, instead they provided the zip file for all the files in the site to me; so that now I can host my client's site.
As I don't know anything about Django, can someone please shed a light where I should start from?
Thanks in advance.
Cheers.
Sach
First of all, install Django on the development machine. Start by trying to get the development server run on your machine.
Gather requirements: check the settings.py for installed apps against the default Django settings.py file. See if there are any popular django apps that site depends on. If there are any, then you probably will have to install them, too.
In which format was the database provided? Will you move to another more appropriate format? Python bindings for databases are required too.
Considering the fact that you have inherited this project and probably will need to make some changes, consider installing django-south, so you can easily make changes to the database schema.
If you get the site running properly on your own machine, consider deplyoment. Is there a lot of static content? (if so, consider nginx). Set up apache2 and install the mod_wsgi module. Deploy.
Work your way through the Django tutorial first. Then look into Django Book as has been mentioned. Django IRC channel (#django) on Freenode is also great for help.
Your best bet would be to learn about Django before trying to jump in head first - https://www.djangoproject.com/ contains documentation as well as tutorials on creating Django apps.
Django is fairly easy to setup if you already have the code written. You'll need to install the chosen database and then simply follow the tutorial on the Django website
Django comes with a built-in server so it's very easy to run the website for development without needing Apache, nginx or much else.
I learned using the Django Book. Django is an easy-to-use framework, you should be fine.
Also, in the short-term there's a file called views.py and separate folder containing templates. If you're familiar with MVC (MVT in Django) this contains the views for the site in function form. There's probably (but not always) a folder for templates which contains a lot of the HTML for the site. Just a good starting pointing for basic modifications.
You can perhaps start here. https://docs.djangoproject.com/en/dev/howto/deployment/
First, find out the django version required by your client. Install that on a server (not a production one), setup apache and mod_wsgi. The zip files may go to a dir which can be included in the mod_wsgi configuration.
Find about the static files and setup apache or any other lightweight webserver to server it.
You may not be a developer, but have a try with the django book. It can give you a good idea how its structured.