Django admin logging out on model save - django

I'm running a Django app for my root public_html folder, and it's working fine. But there's a problem with one of my other apps. The problematic app is accessed through a redirect to a subdirectory (e.g. http://workingsite.com redirects to public_html, http://brokensite.com redirects to public_html/foo)
The problem is that the session expires whenever anything needs to be saved in the Django admin (either added or changed). If you try again, sometimes it works. This does not happen on my own machine when I run the Django dev server.
The timezone in both of the app settings.py files is the same, which is the same as the timezone in both of the .htaccess files.
The apps are almost identical, except the working app uses WYMEditor and the broken one uses TinyMCE as its text editor. Don't know why that would do anything to cause the problem, but I included it just in case. Also, I've made a custom CSS file for the admin backend in the broken app (again, shouldn't cause a problem).

Seems to have been a configuration issue with the company I was hosting with - it's not happening anymore.

Related

Serve multiple Django applications from one server

Good morning. I have a dedicated ubuntu server behind my company's firewall. It is using Django, Gunicorn, and Nginx to serve an Intranet application to employees. The original app responds to the URL [server_name]/[original_application_name]. I want to serve additional apps from this server. I have followed this tutorial as I did when setting up the original app.
I can run Gunicorn and serve the app, I have created a second systemd service file that appears steady (copied from the original app with paths changed - service runs), same for a new 'sites-available' file in Nginx (copied from original and modified), new .sock file exists, binding appears successful. However, I have yet to hit on the right configuration combination between settings.py [allowed_hosts], [new_app].service, and nginx etc.
The original app is running and when I try a URL related to the new app it gives an error saying it cannot find the request in the url.py of the original app. The new app would be used by the IT dept. Ideally, the new URL would be something like: it.[server_name]/[new_application_name].
I have looked through other cases with this problem but most use Apache or are on a public hosting site. I have seen this but it requires a "socket file". My original app is not using a socket file. I was hoping to do this without interfering with the original app. Is a "socket file" required? How can I configure this to serve both apps? Never having done this, what will the new URL be? The URL for the admin site in both apps is 'admin/', how can I accommodate this? Thanks!
I combined into one file as you suggested and I am almost there! I have original site responding at [server_name]/inventory and new site responding at [server_name]/assets. Great! My only problem is the admin page. In both apps the admin site is called admin! So, [server_name]/admin brings up the original site. How can I get to the new admin page?

Django app copied to new location is still accessing old files, because it is using the wrong settings.py

Django version 1.4, using Supervisor, NGINX, gunicorn, and postgresql 8.4. The project where an app was located has been moved to a different server which also has the domain now. I had another project hosted on this same server, and I want to move my app over to that project with all database data intact.
I moved the app files (models.py, views.py, etc.) to a folder in the destination project, moved the templates to corresponding folders, added the app to the destination project's settings.py, and ran manage.py syncdb. Using PGAdmin's backup and restore I moved all of the data over. After updating some relative references in the python files I was able to access all of the database data (which seems entirely intact) in the Django admin site.
Now the problem: the new urls seem to work fine, but it is using the old project's .py files and all templates. I even commented out the app in the settings files of both new and old projects and all it did was hide the admin site from me.
To identify the problem I inserted a typo into the old project views.py, and got it to throw a traceback, which let me see that it was using the old project's settings.py instead of the new one. How do I make the app switch to the new project settings.py? How is it even finding the old one?
I realize after the fact that this question probably belongs on Server Fault instead of Stackoverflow. I did figure this out, though, and posted the answer on SF:
https://serverfault.com/a/722742/311615

hostgator not recognizing urls.py of Django project

I am working within the File Manager of Hostgator and have already set up a Django project which displays "It worked! Congratulations on your first Django-powered page." Following this, I ftp'ed my local Django project (which works fine on the local server) into File Manager and stored it into a temp folder, copying over the changes to the urls.py, views.py, and settings.py files of the new Django project along the settings path.
However, nothing appears to be changing on the website - it's still on the "Congratulations" page. I've tried moving various templates into different places to see if it responds, but that doesn't appear to be doing the trick. Thoughts?
You need to read documentation about how to manage your project on the hostgator servers

Submitting ImageFields in Django Admin doesn't work

I have some models with ImageFields (that work fine on my home computer test environment). When I put the project on a server using Passenger WSGI, submitting a form in the admin containing an ImageField doesn't work.
If DEBUG is True, I get a 404 error page saying that it can't find 500.shtml (I didn't create a 500 error page). No error appears in the server console.
If DEBUG is False, I get an Apache message saying it can't find "admin/red_projects/project/add/" (the URL it was JUST at), and the server error log has a message saying that the folder admin doesn't exist in the filesystem (since it's not a directory, just a Django urlconf), or it just hangs and doesn't load the page.
I already recursively set the permissions on the media directory to 755, and that didn't do anything. Everything else works fine, including submitting admin forms without ImageFields.
Django dosn't serve media or static files when debug is False, you shoud have and alias in your configuration to serve them via the web server directly (Way faster than using django to serve them)
Read this, it will help you put it in production : Deploying static files
Edit: This is for static files, same things aply to media files

Hosting Django Project at /test #login_required redirects to /accounts instead of /test/accounts

I'm moving a project to new hosting and would like to set it up such that it sits at mysite.com/test/ (this is under mod_wsgi on an Apache server). This seems to do alright for the application itself, but when I use #login_required to enforce authentication Django redirects to mysite.com/accounts/login instead of mysite.com/test/accounts/login as I would like. I also have a mysite.com/prod that I want to do this same thing on so I don't want to hard code this anywhere in settings... it should figure out where the root of its URL is and act accordingly.
How do I set it up so that Django automagically redirects to what Apache considers that application's web root?
You need to set LOGIN_URL and LOGOUT_URL to full URL path in Django settings file. See:
http://docs.djangoproject.com/en/1.3/ref/settings/#login-url
Django doesn't automatically insert the mount point at the start of those as so have to be fully qualified.
The same problem can be solved in a more generic way for all project URLs. You could checkout an alternative solution at Running a Django site on my local machine, am I redirecting my URLs properly? for an environment based ROOT URL support.