URL configuration issue with Django app using Bluehost - django

I'm in the process of deploying my Django app to a production server using Bluehost but keep seeing my site's 404 page. The issue seems to be my URL configuration. When I type http://www.example.com/ into my browser I receive the following :
Request URL: http://www.example.com/public_html/
^main/
^admin/
^accounts/
^media/(?P<path>.*)$
etc..
The current URL, public_html/, didn't match any of these
public_html/ is automatically added to the end of my URL I would like to eliminate the public_html/ entirely so my URL pattern will work as expected. For example
Request URL: http://www.example.com/
Which would then redirect to
Request URL: http://www.example.com/main/
How would I go about changing the default from http://www.example.com/public_html/ to http://www.example.com/ ?
My fcgi file:
AddHandler fcgid-script .fcgi
RewriteEngine on
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(adminmedia/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(cgi-bin/mysite.fcgi)
RewriteRule ^(.*)$ cgi-bin/mysite.fcgi/$1 [L]
My .htaccess file:
#!/home/username/python/bin/python
import sys, os
sys.path.insert(0, "/home/username/python")
sys.path.insert(13, "/home/username/MySite")
os.environ['DJANGO_SETTINGS_MODULE'] = 'MySite.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
Is there a possibility this could be an issue with where my files are located on my server? If anyone has experienced this kind of issue before I would greatly appreciate some advice. Thanks!

You have to define following url in your urls.py,
url(r'^$', 'views.home', name='home')
url(r'^main/$', 'views.main', name='main')
then in views.py
def home(request):
return HttpResponseRedirect('/main/')
def main(request):
#some code here.

Related

Django Response Delay for every request

currently, I move my Django application on a production server. The problem is that each request to the server is slower by 1 second, then locallhost. (I don't mean static files. For testing I made ​​a simple VIEW, that not access the database and not contain python code only return string) I did get this values(delay 1 second) ​​of Chrome / Network/ Property - request - Waiting. Property Sending/receiving is normal (cca 1-10ms)
My .htaccess:
AuthType none
Satisfy Any
Allow from All
AddHandler fast-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /mysite.cgi/$1 [QSA,L]
My mysite.cgi:
#!/usr/bin/python
# -*- coding: utf8 -*-
import sys, os
# to suppress browser output, you should explicitly say so.
import cgitb
cgitb.enable(display=True)
# Add a custom Python path.
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ.setdefault("DJANGO_SETTINGS_MODULE","Web.settings")
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="False")
I'm not server admin, so haven´t permission for setting Apache etc.
It is possible that the application not uses FastCGI but CGI? Or something like that?
Thanks
Problem solved by server admin, the server has not installed mod_fcgid.

Django redirect loop in form submit

Just to clarify, this is the first time I'm putting a django website to production.
I have a simple website in django that works locally. But when I deploy it in the production server it enters in redirect loop when I submit a form. Then the browser just tells me that a redirect loop occurred and asks to empty the cache and so on...
This problem happens in the admin. I don't know if it would happen in the frontend because it just doesn't have any form in the frontend.
Notes:
I don't have any funky middlewares.
I tested in a virtual machine with more or less the same specs of
the production server and it works fine.
The submitted data is correctly handled and saved
The rest of the website is fine
I'm using apache with wsgi in a shared host, through a .htaccess.
At this point I don't rule out the chance of a dns misconfiguration, but I already checked and looks fine.
.htaccess:
AddHandler wsgi-script .wsgi
DirectoryIndex app22.wsgi
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app22.wsgi/$1 [QSA,PT,L]
</IfModule>
app22.wsgi:
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'BTT.settings'
path = '/home/bttmonch/apps'
if path not in sys.path:
sys.path.append(path)
path = '/home/bttmonch/apps/ENV/lib/python2.7/site-packages'
if path not in sys.path:
sys.path.append(path)
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
At this point I created a fresh new app with just the admin activated, to see if it was some codding issue and put it on the server. And the same thing happens.
I am using the same .htaccess and .wsgi files that I mentioned before.
My urls.py is just the basic:
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
I am accessing the app via test.domainname.com.
I already tried accessing it through test.domainname.com, test.domainname.com/app22.wsgi, domainname.com/test/ and domainname.com/test/app22.wsgi...
After poking around in the server I stopped getting a redirect loop. But now every time I save a form I get a 403 error. Than I clear the browser cookies and all comes back to normal, and the form data is successfully saved in the database.
At this point a just don't now what else to try...

Django FastCGI and 500 Internal Server Error

I tried to install Django with FastCGI but without success!. It gives me a 500 Error, but if I execute my ./dispatch.fcgi on shell it gives me the "it works!" HTML page of Django.
Here is my url http://mydjango.webmashing.com
and my dispatch.fcgi file is
#!/usr/bin/python
import sys, os
sys.path.insert(0, "/home/webmashi/.local/lib/python")
os.chdir("/home/webmashi/.local/lib/python/myproject")
os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
.htaccess file:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]
I update my python version from 2.4 to 2.6 and it's worked :)

FCGI htaccess handler

I'm trying to setup django on a shared hosting provider. I followed the instructions on http://helpdesk.bluehost.com/index.php/kb/article/000531
and almost have it working.
The problem I'm facing now is that the traffic is properly routed throught the fcgi file, but the file itself shows up as plain text in the browser. If I run ./mysite.fcgi in the ssh shell, I do get the default django welcome page.
my .htaccess is:
AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
and mysite.fcgi:
#!/usr/bin/python2.6
import sys, os
os.environ['DJANGO_SETTINGS_MODULE'] = "icm.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
thanks.
Try removing AddHandler, or changing it to:
AddHandler fcgid-script .fcgi

django urlconf or .htaccess trouble

I am running my django project from subfolder of a website. Lets say the address where my project is meant to open from is.
http://example.com/myproject/
the myproject folder is root folder for my user account. In that folder i have fcgi script that starts my project. The .htaccess file in the folder contains this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
The trouble is, that at some cases, instead of redireting user to page like
http://example.com/myproject/social/someurl/
it redirects to
http://example.com/social/someurl/
which does not work. What i want to know is how to fix this problem.
Redirects in django-socialauth (github.com/uswaretech/Django-Socialauth), socialauth.views.py line 177 redirects without /myproject/, similar to the generic example above. I also use django cms2.0 in the project and it redirects user at admin auth to example.com/en/myproject/admin/, not example.com/myproject/en/admin. But that could be django cms's problem.
Is this kind of behaviour django problem and i should change it with urconf and add myproject to all urls, or should i do this with .htaccess? I found similar question, which, sadly, remains unanswered:
How to write .htaccess if django project is in subfolder and subdomain?
Alan.
It's seems that django-cms-2.0 add the locale prefix to the url using the middleware level. Very well indeed.
But what's more interesting is that they prefix all of the url using resolve('pages-root')
So, you might be able to do this in the urls.py instead...
if not settings.DEBUG:
urlpatterns += patterns('',
url(r'^myproject/$', details, {'slug':''}, name='pages-root')
)
Just make sure that you append the above urlpatterns before the cms.urls.
What if you try
RewriteRule ^(myproject/.*)$ mysite.fcgi/$1 [QSA,L]
Set the RewriteBase:
RewriteEngine On
RewriteBase /myproject/
In /urls_production.py
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^myproject/', include('urls')),
)
In /settings_production.py
from settings import *
ROOT_URLCONF = 'urls_production'
Make sure you set DJANGO_SETTINGS_MODULE to settings_production in the server environment.