我最近转移到另一台机器,不得不再次从subversion检查我的项目,但我很确定这台计算机有Django 1.8,项目预计1.7.
我试图将我的数据库与代码同步以创建必要的表但我收到以下错误.
C:\Users\jont\Documents\ATP\Webapp>manage.py syncdb
C:\Python27\lib\site-packages\admin_tools\utils.py:9: RemovedInDjango19Warning:
django.utils.importlib will be removed in Django 1.9.
from django.utils.importlib import import_module
c:\users\jont\documents\django-trunk\django\contrib\contenttypes\models.py:148:
RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't de
her isn't in an application in INSTALLED_APPS or else was imported before its application was
loaded. This will no longer be supported in Django 1.9.
class ContentType(models.Model):
C:\Python27\lib\site-packages\admin_tools\dashboard\modules.py:8: RemovedInDjango19Warning: The
django.forms.util module has been renamed. Use django.forms.utils instead.
from django.forms.util import flatatt
C:\Python27\lib\site-packages\django_tables2\tables.py:171: RemovedInDjango19Warning: SortedDict
is deprecated and will be removed in Django 1.9. attrs["base_columns"] …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用DecimalFormat格式化价格,但这不适用于所有变体.
DecimalFormat df = new DecimalFormat("0.##")
df.format(7.8)
df.format(85.0)
Run Code Online (Sandbox Code Playgroud)
版画
7.80
Run Code Online (Sandbox Code Playgroud)
和
85
Run Code Online (Sandbox Code Playgroud)
但"7.79999"格式为"7.8",而不是"7.80".我试过这样做
DecimalFormat df = new DecimalFormat("0.00")
Run Code Online (Sandbox Code Playgroud)
强制两个dp,但"85.0"格式化为"85.00"而不是"85"!
有没有办法捕捉所有变化,以便价格打印为#,##或#.##?例如:
5,55,5.55,5.50,500,500.40
我有一段代码通过POST从表单中获取文件.
file = request.FILES['f']
Run Code Online (Sandbox Code Playgroud)
将此文件保存到我的媒体文件夹的最简单方法是什么?
settings.MEDIA_ROOT
Run Code Online (Sandbox Code Playgroud)
我正在看这个答案,但其中有错误引用了未定义的名称和无效的"块"方法.
必须有一个简单的方法来做到这一点?
我的views.py中的EDIT上传方法:
def upload(request):
folder = request.path.replace("/", "_")
uploaded_filename = request.FILES['f'].name
# create the folder if it doesn't exist.
try:
os.mkdir(os.path.join(settings.MEDIA_ROOT, folder))
except:
pass
# save the uploaded file inside that folder.
full_filename = os.path.join(settings.MEDIA_ROOT, folder, uploaded_filename)
fout = open(full_filename, 'wb+')
file_content = ContentFile( request.FILES['f'].read() )
# Iterate through the chunks.
for chunk in file_content.chunks():
fout.write(chunk)
fout.close()
Run Code Online (Sandbox Code Playgroud) 我正在编写一个Android购物管理器应用程序,并在尝试关闭我的一个SQLite数据库表时遇到错误.
ItemsDb idb = new ItemsDb(this);
idb.open();
ArrayList<String> itemNames = idb.getItemNames();
for(int i=0; i < itemNames.size(); i++){
String itemName = itemNames.get(i);
String itemID = idb.getItemID(itemName);
String itemName = idb.getItemNames().get(i);
String itemPrices = idb.getItemPrices().get(i);
String itemQuantity = idb.getItemQuantities().get(i);
String dateBought = idb.getDateBought(itemName);
String decayRate = idb.getDecayRate(itemName);
String decayType = idb.getDecayType(itemName);
String lastDecay = idb.getLastDecay(itemName);
String prevQuantity = idb.getPreviousQuantity(itemName);
}
idb.close();
Run Code Online (Sandbox Code Playgroud)
对于这个类的其他调用不会发生这种情况,所以我想知道是否因为这里有一个循环,有很多对数据库的调用.错误是SQLite Exception: unable to close due to unfinalised statements.
"ItemsDb"类的错误行在这里
public ItemsDb(Context c){
ourContext = c;
}
public ItemsDb …Run Code Online (Sandbox Code Playgroud) 我有一个运行arch linux的raspberry pi连接到电视,并希望通过SSH从我的Ubuntu机器在其他地方运行命令.
我已经尝试运行命令SSH -Y root @并启动xclock作为测试.但是我收到以下错误:
没有指定协议错误:无法打开display :: 0
然后我尝试在arch机器上运行"export DISPLAY =:0",但这并没有解决问题.
我有X运行正常,可以在电视上看到它,我已编辑文件/ etc/ssh/ssh_config以允许X11转发.
谁知道我做错了什么?
非常感谢
我一直在看本教程,现在/static/styles/ 中有一个样式表。
问题是模板没有选择这个:
<html>
<head>
<link rel="stylesheet" type="text/css" href="static/css/stylesheet.css" />
<title>Search</title>
</head>
<body>
...
Run Code Online (Sandbox Code Playgroud)
我的设置文件中是否需要某些内容?我哪里错了?
我的项目结构是:
project
- manage.py
- project
- static
- templates
- __init__
- etc..
Run Code Online (Sandbox Code Playgroud)
编辑 我的 urls.py 现在看起来像这样:
from django.conf.urls import patterns, include, url
from bible import views
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'bible.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^verses/', views.search),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Run Code Online (Sandbox Code Playgroud)
这是我的 …
我刚刚创建了一个Django项目
python manage.py startapp smartrecruitment
Run Code Online (Sandbox Code Playgroud)
然后我运行了db sync
python manage.py syncdb
Operations to perform:
Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying sessions.0001_initial... OK
Run Code Online (Sandbox Code Playgroud)
并添加了我的超级用户,但我无法在浏览器中访问/ admin.我尝试过以下命令来授予apache权限,但没有运气.
sudo chown apache <folder_containing_db.sqlite3>
sudo chown apache db.sqlite3
Run Code Online (Sandbox Code Playgroud) 我有一个电子邮件模板:
<html>
<head>
<style>
#outer_content {
background-color: #F7F7F7;
border: 1px solid #E4E4E4;
width: 100%;
height: 100%;
}
#email_content {
max-width: 650px;
font: 12px Georgia, "Times New Roman", Times, serif;
color: #888;
text-shadow: 1px 1px 1px #FFF;
margin-left: 25px;
margin-top: 15px;
margin-right: 25px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div id="outer_content">
<div id="email_content">
<h2>New message from {{ user }} ( {{ email }} )</h2>
<p>Message below:</p>
<p>{{ message }}</p>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
它在浏览器中显示良好,但 Outlook 似乎被边缘混淆了。我试过使用填充,但这没有帮助。为了解决这些问题,我需要知道任何 css 技巧吗?

我有一个模型,它有一个日期字段
date_of_birth = models.DateField(blank=True, null=True, verbose_name="DOB")
Run Code Online (Sandbox Code Playgroud)
我想格式化它以格式保存日期dd/MM/yyyy,但我尝试过的所有内容都失败了.
我认为默认必须是YYYY-MM-dd因为它是如何保存到我的数据库.尝试以不同的格式提交日期会出现错误:
[u"'17/01/1970' value has an invalid date format. It must be in YYYY-MM-DD format."]
Run Code Online (Sandbox Code Playgroud)
我尝试过使用Date Widgets,但是我遇到了一些问题,因为它与我的models.py兼容
我有一个表格:
class ReferencesForm(forms.ModelForm):
error_css_class = 'error' #set some css when an error
contactName = forms.CharField(label='Contact Name:')
company = forms.CharField(label='Company:')
address = forms.CharField(label='Address:')
telephoneNumber = forms.CharField(label='Telephone Number:')
class Meta:
fields = '__all__'
model = References
def __init__(self, *arg, **kwarg):
super(ReferencesForm, self).__init__(*arg, **kwarg)
self.empty_permitted = True
def clean(self):
""" Custom validation for fields
"""
cleaned_data = super(ReferencesForm, self).clean()
return self.cleaned_data
Run Code Online (Sandbox Code Playgroud)
并在我的视图文件中构建它,如下所示:
ReferencesInlineFormSet = inlineformset_factory(
Applicant, References, form=ReferencesForm, extra=1, can_delete=False)
...
if request.method == 'POST':
references_formset = ReferencesInlineFormSet(
request.POST, instance=applicant)
if (references_formset.is_valid()):
references_formset.instance['address'] …Run Code Online (Sandbox Code Playgroud) 我正在编写一种将一些 JSON 写入文件的方法,该方法工作正常。但是,尽管我已将输出设置为 UTF-8,但Oxygen无法读取英镑和欧元符号。
爪哇代码:
Path logFile = Paths.get(this.output_folder + "/" + file.getName().split("\\.")[0] + ".json");
try (BufferedWriter writer = Files.newBufferedWriter(logFile, StandardCharsets.UTF_8)) {
File fileDir = new File("test.json");
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));
ObjectMapper mapper = new ObjectMapper();
writer.write(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(all_questions));
}
Run Code Online (Sandbox Code Playgroud)
"all_questions" 是一个 Question 对象的数组列表,它被 ObjectMapper 打印为格式化的 JSON 片段。
一些带有英镑符号的示例 JSON 如下所示:
{
"name" : "RegExRule",
"field" : "Q039_4",
"rules" : [ ],
"fileName" : "s1rules_england_en.xml",
"error" : null,
"pattern_match" : {
"$record.ApplicationData.SiteVisit.VisitContactDetails.ContactOther.PersonName.PersonGivenName" : "^[\\u0000-\\u005F\\u0061-\\u007B\\u007d-\\u007f£€]*$"
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spring为我的网站创建一个缓存类,并将以下代码添加到我的applicationContect.xml文件中:
<bean id="SiteCache" class="Cache.SiteCache">
Run Code Online (Sandbox Code Playgroud)
我不确定的是如何初始化这个类.我是否需要自己初始化它,或者当网站加载时Spring会处理它吗?如果是这样,我将如何接受构造函数中的参数?
我希望这个类大部分时间都可以使用,作为访问变量来填充站点的一种更快的方法,但我需要一种方法来检查是否有一个实例,以便我可以加载XML文件来自其他来源.
在春天实现缓存的最佳方法是什么?
非常感谢,
我有一个正则表达式,当前与任何非数字字符匹配:
var.replace(/[^0-9a-zA-Z ]/,'');
Run Code Online (Sandbox Code Playgroud)
我现在需要保留空格和数字,但是我很难修改它。
有什么帮助吗?
django ×6
python ×3
django-1.7 ×2
django-forms ×2
java ×2
android ×1
apache ×1
css ×1
database ×1
django-views ×1
html ×1
html-email ×1
javascript ×1
json ×1
linux ×1
outlook ×1
python-2.7 ×1
python-3.x ×1
raspberry-pi ×1
regex ×1
singleton ×1
spring ×1
spring-mvc ×1
sqlite ×1
ssh ×1
ssh-tunnel ×1
utf-8 ×1