How to use django "site" framework on google app engine - django

I'm going to answer my question. I ask this so that other people who is still searching on how to create a django "site" will have a clear answer.
The django documentation had show how to use the django site framework. But strangely, after googling for quite a while, I can't find a good instruction on how to install the site framework. We all know to install an app, we put 'django.contrib.sites' on the INSTALLED_APP list. But how to add the site? Using the admin interface will result in error that say that the site framework is installed but no site is configured (Duhh!). So, we have to assign SITE_ID on the setting.py. But what is the id? From some source, we know that the it has installed a default site by the domain example.com. But still what is the id? setting it to 0 or 1 will also result in error.

Just read the link:
http://www.allbuttonspressed.com/projects/djangoappengine

Definitely the best tutorial I have found:
Flying with Django on GAE
With this I had my site on appspot after about half an hour.

The answer is....
First, put 'django.contrib.sites' on the installed app list like usual.
Then run
python manage.py syncdb
(At you project directory that is). Then, run:
python manage.py shell
Then, use the following sequence of code:
>>>import django.contrib.sites.models as mod
>>>mod.Site.objects.all().count()
Make sure it prints out 1. If it doesn't you probably haven't run syncdb properly.
>>>msite=mod.Site.objects.all().get()
>>>msite.pk
It will print your default site id. SITE_ID (in setting.py.)to the number given. That should do it. At least on development server.
ps: Strangely, mine is 383L. Not 0 or 1. This is probably google app engine with django nonrel specific.

Related

How to set virtualenv to stay active on a host server

I created a website that uses vuejs as the frontend and django as the backend with another service running behind everything that im making api calls to.
So django is setup in a way to look at the dist folder of Vuejs and serve it if you run manage.py runserver. but the problem is that my service that I created is
is also in python and it needs to run in a virtualenv in order to work (It uses tensorflow 1.15.2 and this can only run in a contained environment)
I'm sitting here and wondering how I can deploy the django application and keep the virtualenv active and Im coming up with nothing, I've tried doing some research on this but everything I found was not relevant to my problem. I've deployed it and when I close the ssh connection the virtualenv stops.
If there is anyone that can enlighten my ways I would appreciate it.
i think you need to nginx: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
if you are search for keep states just in terminal i suggest tmux https://github.com/tmux/tmux/wiki
You can use uWSGI and nginx to deploy Django apps on server. Here's helpful articles:
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
Django official docs also has a page about it: https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/uwsgi/
There are articles from developers so you can refer them in case you get stuck anywhere:
https://www.freecodecamp.org/news/django-uwsgi-nginx-postgresql-setup-on-aws-ec2-ubuntu16-04-with-python-3-6-6c58698ae9d3/
https://medium.com/#biswashirok/deploying-django-python-3-6-to-digital-ocean-with-uwsgi-nginx-ubuntu-18-04-3f8c2731ade1

Django perpetual 404s when visiting project directory URL

I have a very strange problem with Django and OLS. I am using the OpenLitespeed Django one click install droplet on Digital Ocean. In both my custom app and the example app in the droplet, if I visit a URL that matches the django project directory (in the example app, this is /demo/), then any subsequent page visits give a 404 error, no matter what URL you do. To reproduce, I've spun up a completely clean install of the droplet, then do the following steps:
Go to / -> see "Hello world!" as expected
Go to /demo/ -> also see "Hello world!" even though this should be a 404, as this URL is not specified in the urls.py or anywhere else
Go back to / -> 404! It seems to be looking for /demo/demo/ which doesn't exist
Trying any other URL also results in a 404.
The only way to get back to the normal behavior is to restart the OLS process. Everything then functions as expected unless any URL that starts with the project directory name is visited, in which case the whole thing crashes and returns 404s again.
Any help that can be provided to try and further troubleshoot this or possible fixes is greatly appreciated!
Versions:
OLS 1.6.9
Django 2.2 and 3.0
Python 3.6
Thanks for the bug reporting. It's a bug of "virtual context settings for wsgi" and should already fixed on version 1.6.11. If it's not on the repository, you can run the following command to upgrade it.
/usr/local/lsws/admin/misc/lsup.sh -v 1.6.11
Best,
Eric

Django models missing. Why my django models disappeared on production server, if on development server runs fine?

im running django development server and all models works fine..
But when i have configured and run apache through wsgi, only "Groups" and "Users" could be administrated, my own models disappears:
screenshot of admin pages from development server and production server
Why, please?
(After first comments here is my edit:)
I want to use django on localhost only, to fill and administrate small database file. Project is not intended for web hosting yet. I have no html views and templates defined. So I have try some simple view for testing purposes only, and problem is the same. Web server cant find some includes..:
image2: simple view also dosen't work
Make sure your production settings file has all the apps included. Normally when you don't see your admin models its due to the app missing from the list of apps included in settings.py.
Had the exact same problem. Had to restart uwsgi
sudo service uwsgi restart
Maybe for you it's wsgi or apache. Something in the pipeline needs to know you changed some python code.

On Dreamhost, how can I get "django-admin startproject" to correctly set up a project in the way django 1.4 is supposed to?

I'm hosting my website on Dreamhost and I've actually managed to get django working for the most part. The one thing I'm still struggling with is to get django-admin to behave like the version from 1.4 instead of 1.2 (which is what dreamhost runs). I set up a virtualenv and such following these instructions http://blog.oscarcp.com/?p=167 . Any help is appreciated!
It sounds like you're not entering into your virtualenv before you run django-admin. What does django-admin.py --version say?

Django through apache

I am having a great deal of trouble deploying a django website written for 1.3 behind apache using django 1.4 and wsgi. There is also a wordpress site running on the same domain too. Ideally I would like to have django site running on [domain]/app/.
Does anybody have any links to a good tutorial. I am having a lot of trouble working out where to put wsgi.py file. It keeps saying it cannot find it.
When I was recently working to deploy my first django project, I found this tutorial helpful. It independently tests if django and wsgi are working using simple "hello world" applications for each and gives an example of how to make the wsgi.py file work right. I think it's not really a question of putting wsgi.py in the right place; it's more a question of telling Apache where wsgi.py is. If you can get the tutorial working it ought to be relatively straightforward to get your full django site working.
For the Django site, should simply be a matter of having:
WSGIScriptAlias /app /some/path/project/wsgi.py
In other words, the '/app' mount point is used with WSGIScriptAlias instead of '/' that many examples use.
If using login features, you may also need to set LOGIN_URL etc in Django settings file however, as it doesn't automatically incorporate in the mount point.