我的Django Logger在我的本地机器上工作正常但在我将它部署到服务器时不起作用.
在我运行的本地设置中python manage.py syncdb,这将创建一个survey.log文件,然后我将其跟随,tail -f survey.log以便在创建时看到错误消息.
在我运行的服务器上python manage.py syncdb,这将创建一个survey.log文件,然后我将其跟随tail -f survey.log.但是我看不到任何调试消息,当我检查文件时nano它是空的.
为什么survey.log我的生产环境中没有记录任何记录数据?我错过了什么?
views.py
import logging
logger = logging.getLogger(__name__)
logger.debug('This is your images list in 7: %s', images)
Run Code Online (Sandbox Code Playgroud)
settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'applogfile': {
'level':'DEBUG', …Run Code Online (Sandbox Code Playgroud) 我正在将一项调查从一个调查转换Form为一个ModelForm在Django 1.6.2中.
谁能告诉我什么是平等forms.ChoiceField(widget=forms.Select(),和forms.ChoiceField(widget=forms.RadioSelect()使用ModelForm?
我试过了widget=models.Select(),widget=models.RadioSelect()但它一直在给出错误
AttributeError:'module'对象没有属性'Select'
AttributeError:'module'对象没有属性'RadioSelect'
forms.py
class SurveyFormB(forms.Form):
#Do you own a Smartphone?
YES_SMARTPHONE = 'Yes'
NO_SMARTPHONE = 'No'
SMART_PHONE_OWNERSHIP = (
(YES_SMARTPHONE, 'Yes'),
(NO_SMARTPHONE, 'No'),
)
smart_phone_ownership = forms.ChoiceField(widget=forms.RadioSelect(), choices=SMART_PHONE_OWNERSHIP, initial= "", label='Do you own a Smartphone?', required = False)
#If 'Yes' How many hours a day do you access the Internet on it?
SMART_PHONE_LESS_THAN_ONE_HOUR_A_DAY = 'Less than one hour day'
SMART_PHONE_ONE_TO_TWO_HOURS_A_DAY = …Run Code Online (Sandbox Code Playgroud) 这似乎是一个非常常见的错误,有几个不同的解决方案, python:UnboundLocalError:在赋值之前引用的局部变量'open'
Python:UnboundLocalError的帮助:在赋值之前引用的局部变量
我的问题不同的地方是我在运行的代码中没有变量"resp".大多数其他问题都已发布,因为海报对类和变量使用了相同的名称,或者未能将其声明为全局变量.
代码
import tweepy
auth = tweepy.OAuthHandler('75VSSMGC4pfUB5u0Zt5G3Q', '2olQeiquDg71uwnGoU2c9e2u3qy2LrKkn2p6KWBIdI')
auth.set_access_token('122095773-cCrYa4FWFoBkx44LES8yeBlt8DTG0jnZivJ79k2J', 'p1Nmp9DaPUIThpTamzIMfdvJu0wgdfxmghdwsSagM')
api = tweepy.API(auth)
print api.rate_limit_status()
#print tweepy.api.rate_limit_status()
Run Code Online (Sandbox Code Playgroud)
错误
Traceback (most recent call last):
File "/Users/brendan/Documents/workspace/Tweeter/src/rate_limit.py", line 6, in <module>
print api.rate_limit_status()
File "build/bdist.macosx-10.5-fat3/egg/tweepy/binder.py", line 185, in _call
File "build/bdist.macosx-10.5-fat3/egg/tweepy/binder.py", line 147, in execute
UnboundLocalError: local variable 'resp' referenced before assignment
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我只是在学习Java,在Deitel和Deitel的书"Java如何编程"中阅读教程,所以请原谅我正在犯的任何基本错误.我理解我的方法可能不是最好的,但我希望能够改进这一点.
我的问题是我相信我错误地构建了我的程序.执行程序时,正在输出IF和ELSE选项.
如果有人能告诉我为什么两个选项都在执行,那将非常感激
困境
package controlStatments;
import java.util.Scanner;
public class Review_4_20
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
//Declare Variables
double employeeOneRate;
double employeeOneHours;
double employeeTwoRate;
double employeeTwoHours;
double employeeThreeRate;
double employeeThreeHours;
int calculator;
double employeeOneTotalPay;
double employeeOneNormalPay;
double employeeOneTotalPayOverTime;
double overTimeRate;
//Initiate Variables
employeeOneRate = 0;
employeeOneHours = 0;
employeeTwoRate = 0;
employeeTwoHours = 0;
employeeThreeRate = 0;
employeeThreeHours = 0;
calculator = 0;
employeeOneTotalPay = 0;
employeeOneTotalPayOverTime = 0;
overTimeRate = 1.5;
employeeOneNormalPay …Run Code Online (Sandbox Code Playgroud) 刚运行Django教程4,我想知道是否有人可以告诉我...打开类后在外壳中出现的三个点的名称,以及如何>>>正确返回正常状态?
该shell被访问 python manage.py shell
>>> class SilentAssertionError(AssertionError):
... silent_variable_failure = True
>>> class PersonClass4:
... def first_name(self):
... raise SilentAssertionError
>>> p = PersonClass4()
>>> t.render(Context({"person": p}))
u'My name is .'
Run Code Online (Sandbox Code Playgroud)
EG到达行尾
... raise SilentAssertionError
Run Code Online (Sandbox Code Playgroud)
当我按回车键时,仍然会...出现提示。如果我在此处输入下一行,则会出现错误。到目前为止,我一直在做两次击退以使其恢复正常的操作>>>
也有一个名字>>>吗?
在我创建的多页调查应用程序中,我有一个jQuery UI滑块,用于为图像提供评级.这会将数值返回到我的Python/Django视图,该视图存储在列表中slider_DV_values
在稍后的数据验证调查页面上,参与者可以通过另一个jQuery滑动条获得机会,以更新他们为图像分配的评级.
我的问题是,如果参与者更改它,jQuery UI滑块栏只会返回一个数值.因此,如果参与者没有更新,则原始评级将被覆盖,没有任何内容.
但是,如果他们确实更新了他们的评级,则会存储新值.
如果我试试
elif step == 13:
slider_value1 = self.request.POST.get('slider_value1')
print "This is slider_value1", slider_value1
if slider_value1 is not None:
slider_DV_values.pop(0)
slider_DV_values.insert(0, slider_value1)
Run Code Online (Sandbox Code Playgroud)
存储的原始值slider_DV_values仍然被覆盖,没有任何内容.
我以为is not None会阻止使用空值来覆盖原始值?这不正确吗?
任何人都可以告诉我如何防止原始值被覆盖,除非新值是更新的数值?
谢谢,Deepend
编辑
要查看我如何获取我的值,这是我SurveyWizardView的页面中的jQuery滑块,其值通过隐藏的表单元素返回
<div class="DV_image_row">
<div class="DV_image_left">
<img src="{% static "survey/images/pathone/" %}{{first_image}}{{fourth_image}}{{seventh_image}}" height="300" width="250" style="border:1px solid black;" align="middle"/>
<div class="DV_slider_one" id="one"></div>
<script >
$('#submit').click(function() {
var username = $('#hidden').val();
if (username == "") username = 0;
$.post('comment.php', {
hidden: username
}, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个程序,它接受用户输入的字母,读取文本文件,然后打印以该字母开头的单词.
item = "file_name"
letter = raw_input("Words starting with: ")
letter = letter.lower()
found = 0
with open(item) as f:
filelength = sum(1 for line in f)
for i in range (filelength):
word = f.readline()
print word
if word[0] == letter:
print word
found += 1
print "words found:", found
Run Code Online (Sandbox Code Playgroud)
我一直收到错误
"如果word [0] == letter:IndexError:字符串索引超出范围"
没有印刷线.我认为如果没有任何内容会发生这种情况,但文件中有50行随机单词,所以我不确定为什么会这样读.
django ×4
python ×4
python-2.7 ×2
apache ×1
django-forms ×1
django-views ×1
if-statement ×1
java ×1
logging ×1
shell ×1
tweepy ×1
while-loop ×1