2

I'm hoping someone can help me out with this issue I'm having as it seems like a simple one but I've been banging my head on this for the past couple hours with no solace. OK, so I set up Django following the A2 Hosting guide here.

And I'm just not able to communicate with my views.py file.

Let me show you some files as I'm hoping its just some blatant error.

public_html/mysite/mysite/setup.py:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'nfl'
)

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': '*******',
    'USER': '*******',
    'PASSWORD': '***',
    'HOST': '',
    'PORT': '5432',
}
}
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
    "nfl/templates",

)

public_html/mysite/mysite/urls.py:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^home/', 'nfl.views.home', name='home'),

]

public_html/mysite/nfl/views.py:

from django.shortcuts import render_to_response
import nfldb
import requests
# Create your views here.
def home(request):
    db = nfldb.connect()
    q = nfldb.Query(db)
    year = request.GET['year']
    if year is none:
            year = 2014


    q.game(season_year=year, season_type='Regular')
    qb = []
    for pp in q.sort('passing_yds').limit(10).as_aggregate():
            qb.append(pp)
    return render_to_response('index.html', {'qb' : qb})

public_html/mysite/nfl/templates/index.html:

just a helloworld html file to test

.htaccess:

AddHandler fcgid-script .fcgi
RewriteEngine on
# Set up static content redirect:
RewriteRule static/(.+)$ mysite/public/static/$1
# The following two lines are for FastCGI:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application.fcgi/$1 [QSA,L]

And when I go to my domain, I just get the basic congrats on your first Django app page.

So what am I missing here? I copied most over from my local machine because it was working there on the local host with the Django runserver but now I can't seem to link my views.

Let me know if there's any other info needed or if there's a better website to go to.

My setup:

  • Python: 2.7
  • Django: 1.85
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • @@panthor314 By "when I go to my domain" do you mean domain.com? Because in your URLs.py, in order to access your "home" view, you have to go to "^home/" i.e. domain.com/home – SilentDev Oct 19 '15 at 02:25
  • wow that seemed to work(THANKS!!!)... now its saying no module named requests eventhough its installed... –  Oct 19 '15 at 02:29
  • Is it pointing to the "import requests" line in your views.py when it raises the "no module named requests" error? If yes, it seems like requests is not a built-in module. See the answer here: http://stackoverflow.com/questions/17309288/importerror-no-module-named-requests Did you install it using "pip install requests" on your production (current) server? If no, how exactly did you install it? – SilentDev Oct 19 '15 at 02:33
  • @user2719875 yeah yeah its pointing to my views.py, but yes i pip installed it on my server, dont know why it wont recognize –  Oct 19 '15 at 02:38
  • can you give me the output of the "pip freeze" command? – SilentDev Oct 19 '15 at 02:39
  • @user2719875 OK so i changed to djangoenv and then installed requests there and that worked now its looking for the config.ini file of my db so hopefully im on the right track! –  Oct 19 '15 at 02:42
  • @user2719875 pip freeze:Django==1.8.5 Paste==2.0.2 beautifulsoup4==4.4.1 enum34==1.0.4 flup==1.0.3.dev20110405 httplib2==0.9.2 nfldb==0.2.11 nflgame==1.2.17 psycopg2==2.6.1 pytz==2015.6 requests==2.8.1 six==1.10.0 wsgiref==0.1.2 –  Oct 19 '15 at 02:43
  • Okay sounds good. I'm going to post my first comment as the answer to this question (because that is the answer to the original question). If you have any other issues, just ask in a new post. This avoids the "ask question x but end up solving question y and z" issue. You can check the answer off if it correctly answers the original question. – SilentDev Oct 19 '15 at 02:46

1 Answers1

0

If you go to domain.com, then the "Congrats on your first django app" page will appear, because in your URLs.py, you do specify a view for

url(r'^')

In order to not show this page, and to show your index.html page instead, you should do

urlpatterns = [
    url(r'^', 'nfl.views.home', name='home'),
]
SilentDev
  • 20,997
  • 28
  • 111
  • 214