Django project to domain, vps - python

I have VPS-server (CentOS 6.8)
I installed Python 3.5.2 and Django 1.10.1 on virtual enviroment
I connected my domain to VPS-server
Now:
django-project:
(venv) /home/django_user/djtest/venv/django_project/django_project
domain:
/var/www/www-root/data/www/mydomain.com
I tried set BASE_DIR in settings.py to '/var/www/www-root/data/www/mydomain.com' but not working
How I can to connect django-project to domain?
Project is still empty, just created

Django project can't be served like this, you need some web-server application like gunicorn or apache too.
Just like you use ./manage.py runserver you need some application to execute your django project corresponsing to command theses application are Gunicorn, ApacheWSGI server and others.
There will be a file wsgi.py that would have created when you created the project it's web server gateway interface it will interact with the above mentioned web-servers and server your django based website.

Related

how can i convert django app to desktop app

I have a Django app up and running on DigitalOcean with Nginx and PostgreSQL. But some clients want an offline version of the app so that their data remains on their systems and they don't have to connect to the internet. One solution is to write the whole app from scratch but that would take time and cost.
I was thinking of a solution where I can convert the Django app into a desktop app with minimal changes i.e. replace CDNs with files and remove functionality that requires internet. But I don't know how can I do this.
I was thinking of electron, i,e, elctron will spawn a child process which will start django's server and then the electron will load 127.0.0.1:8000 in a webview.
But how can I package this app into an executable because it would need python installed and configured on the user's system. Or does python itself has any library that can convert the Django app into a desktop app?
Below is the file structure of my Django project
project_folder/
app_1/
app_2/
app_3/
configurations/
templates/
__init__.py
asgi.py
settings.py
urls.py
wsgi.py
media/
staticfiles/
manage.py
Any help would be appreciated.

There will get cross-domain issue when I deploy the frontend and django backend to remote server

Deploy the test environment to remote server.
I use python manage.py to run the development server for django backend:
python manage.py runserver 8001
and use the apache to listen the 80 port for website frontend.
So, when website request the backend, there is cross-domain issue, because the port is not same.
How to handle this issue correctly if in the development environment? Or if this is impossible, whether only can use distribution environment to realize it?
django-cors-headers may help.
Install it by pip,add 'corsheaders' to INSTALLED_APPS,I only add CORS_ORIGIN_ALLOW_ALL = True to settings.py and the CORS problem is solved.

Is mod_WSGI replacing what apache is doing and how I can make wsgi work at a specific path only

I am quite new to Apache and WSGI, there are a lot of things confusing me.
After a fresh install of apache2 on ubuntu, I can open this URL to see the default apache page http://localhost/index.html, the file is residing in /var/www/html. So this is the function that apache server provices, serving http connection.
Here's the current situation:
I've created a simple Django project and install mod_wsgi onto my apache server,and finally I managed to deploy the project to apache and the page iIve created can be accessed correctly.
BUT now when I try to access the index.html i mentioned above, it shows the url mapping cannot be found(yes I do not have this mapping in the django project).Is Django taking over all the path that point to the server?
How can I make the django project only map to a specific path like http://localhost/Django/[MY URL MAPPING] and keep other url mapping untouched.
So I can access the static HTML(index.html) by accessing http://localhost/index.html/ and access my Django project by accessing http:/localhost/Django/[xxx]
Is this possible? or I have to use another virtual host at another port?
Any help will be much appreciated.
You can do this by mounting Django at a different point:
WSGIScriptAlias /Django /path/to/mysite.com/mysite/wsgi.py
This runs the WSGI application at /Django, and leaves Apache to serve the rest of the files directly.

Hosting Django server on FTP space

I have built a Django project which I'd like to deploy now. I've already tried deploying it on pythonAnywhere which worked. But, my college wants to host it on their server and they have given me some server space and FTP credentials to upload files there. How can I get my Django website on to my college's server and host it from there?
Currently, most popular pattern is to use Nginx and Gunicorn. Gunicorn to run your Django app and Nginx to serve as a reverse proxy for Gunicorn. You need something like Gunicorn, a WSGI compatible application server to serve your Django app. Otherwise, I don't think that's possible.
Read more about how to deploy a Django app here: Deploy a Django app to Digital Ocean

Hosting Django and Path to Project Directory

I am using a digital ocean virtual server to host a django web app. when you create the droplet, it creates a default app in the directory /home/django/django_project/django. However seeing as this isn't the app I want to host, I put my application files into the directory /home/myproject/myapp and updated the gunicorn and nginx configs to point there. However once updating the urls for this app, I am trying to see it online and noticed that the 404 looked like this:
which states that the URLconf is defined in django_project.urls which I had since deleted out of that 'home/django directory. I have reloaded and restarted gunicorn and nginx in an attempt to get django to realize that the project django_project doesn’t exist any more, but no luck. Has anyone run into this before or have any suggestions as to what I should try next?

Categories