我下面這個Django的上Openshift教程部署https://github.com/rancavil/django-openshift-quickstart/wiki/Tutorial-How-create-an-application-with-Django-1.6-on-Openshift的Django部署在Openshift錯誤500
不過,我收到500服務器erorr。這裏是我的代碼:
views.py
# -*- coding: utf-8 -*-
from django.shortcuts import render
from bs4 import BeautifulSoup
from collections import namedtuple
import requests
def results(request):
final_data = []
url ="http://www.15min.lt/cempionatas/futbolas/pasaulio-futbolo-cempionatas-2014?from=fifa-menu"
r = requests.get(url)
soup = BeautifulSoup(r.content)
tables = soup.find_all('table')
for table in tables:
row = table.find_all('tr')
data = [[td.text.strip().encode("utf-8") for td in tr.findAll("td")] for tr in row]
final_data += data
group1 = final_data[:7]
group2 = final_data[7:14]
group3 = final_data[14:21]
group4 = final_data[21:28]
group5 = final_data[28:35]
group6 = final_data[35:42]
group7 = final_data[42:49]
group8 = final_data[49:56]
return render(request, 'results.html', {"group1": group1, "group2": group2, "group3": group3, "group4": group4, "group5": group5,
"group6": group6, "group7": group7, "group8": group8 })
def news(request):
Link = namedtuple('Link', ['title', 'url'], verbose=True)
links = []
url ="http://www.15min.lt/naujienos/sportas/fifa-2014/"
r = requests.get(url)
soup = BeautifulSoup(r.content)
titles = soup.findAll("div", attrs={"class": "vl-article-title"})
for i in titles:
links.append(Link(i.find("h3").find("span").find("a").text, url=i.find("h3").find("span").find("a")["href"]))
return render(request, 'News.html', {"links": links})
def tables(request):
Datas = namedtuple('Datas', 'string url', verbose=True)
url ="http://www.uefa.com/worldcup/season=2014/standings/"
final_data = []
r = requests.get(url)
soup = BeautifulSoup(r.content)
tables = soup.find_all('table')
for table in tables:
row = table.find_all('tr')
data = [[td.text.strip().encode("utf-8") for td in tr.findAll("td")] for tr in row]
head = [[th.text.strip().encode("utf-8") for th in tr.findAll("th")] for tr in row]
for i in data:
if i:
if i[1] == "Netherlands": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/ned.png"))
elif i[1] == "Cameroon": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/cmr.png"))
elif i[1] == "Spain": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/esp.png"))
elif i[1] == "Côte d'Ivoire": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/civ.png"))
elif i[1] == "Japan": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/jpn.png"))
elif i[1] == "Costa Rica": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/crc.png"))
elif i[1] == "Switzerland": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/sui.png"))
elif i[1] == "Bosnia and Herzegovina": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/bih.png"))
elif i[1] == "Iran": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/irn.png"))
elif i[1] == "Nigeria": i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/nga.png"))
else:
flag = i[1][:3] + ".png"
i.insert(1, Datas(i, "http://img.uefa.com/imgml/flags/18x18/" + flag))
final_data += data
group1 = final_data[:5]
group2 = final_data[5:10]
group3 = final_data[10:15]
group4 = final_data[15:20]
group5 = final_data[20:25]
group6 = final_data[25:30]
group7 = final_data[30:35]
group8 = final_data[35:40]
return render(request, 'Groups.html', {"group1": group1, "group2": group2, "group3": group3, "group4": group4, "group5": group5,
"group6": group6, "group7": group7, "group8": group8 })
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'views.home', name='home'),
url(r'^tvarkarastis/', 'polls.views.results', name='results'),
url(r'^lenteles/', 'polls.views.tables', name='results'),
url(r'^naujienos/', 'polls.views.news', name='naujienos'),
)
在localhost一切正常,但在服務器出現問題。錯誤在哪裏?如果你需要更多信息,請說。
UPDATE:settings.py的
調試部分:
if ON_OPENSHIFT:
DEBUG = bool(os.environ.get('DEBUG', False))
if DEBUG:
print("WARNING: The DEBUG environment is set to True.")
else:
DEBUG = True
更新(2):
我使用的virtualenv和我已經安裝在它beautifulsoup4和其他庫。這裏是我的requirements.txt內容:
Django==1.6
YourAppName==1.0
argparse==1.2.1
beautifulsoup4==4.3.2
requests==2.3.0
wsgiref==0.1.2
儘管如此,我收到此錯誤:
No module named bs4
請在settings.py中更改'DEBUG = TRUE'。 – Silwest
爲什麼?在部署時不應該是錯誤的嗎? – user3767139
如果我們沒有看到發生了什麼,我們怎麼能告訴你什麼是錯的? – Silwest