是否有任何不需要API密钥的免费词典API,并允许您在多种源语言和目标语言之间进行选择(尽可能多,至少英语,德语,西班牙语,法语...)?
我有以下django模板(http:// IP/admin/start /被分配给一个名为view的假想视图):
{% for source in sources %}
<tr>
<td>{{ source }}</td>
<td>
<form action="/admin/start/" method="post">
{% csrf_token %}
<input type="hidden" name="{{ source.title }}">
<input type="submit" value="Start" class="btn btn-primary">
</form>
</td>
</tr>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
sources是objects.all()视图中引用的Django模型.每当单击"开始"提交输入时,我希望"开始"视图{{ source.title}}在返回呈现页面之前使用函数中的数据.如何将信息(在本例中为隐藏输入)收集到Python变量中?
这是我的布局:

我面临的问题是可绘制的复选标记.我如何在文本旁边对齐它们,它们都在按钮的中心?这是XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PostAssignmentActivity" >
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_checkmark_holo_light"
android:text="Post" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
应用android:gravity ="center_vertical"拉动文本并将其绘制在一起,但随后文本不再在中心对齐.
我将以下字典传递给渲染函数,源是字符串列表,标题是一个字符串,可能等于源中的一个字符串:
{'title':title, 'sources':sources})
Run Code Online (Sandbox Code Playgroud)
在HTML模板中,我想在以下几行中完成一些事情:
{% for source in sources %}
<tr>
<td>{{ source }}</td>
<td>
{% if title == {{ source }} %}
Just now!
{% endif %}
</td>
</tr>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
但是,以下文本块会导致错误:
TemplateSyntaxError at /admin/start/
Could not parse the remainder: '{{' from '{{'
Run Code Online (Sandbox Code Playgroud)
......以{% if title == {{ source }} %}红色突出显示.
我有一个干净的Android项目与谷歌播放服务转.13通过SDK管理器安装,遵循这些说明.
我的build.gradle文件如下:
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试构建这个应用程序时,我明白了
Gradle: A problem occurred configuring project ':Maple'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':Maple:_DebugCompile'.
> Could not find com.google.android.gms:play-services:4.0.30.
Required by:
MapleProject:Maple:unspecified
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Django-haystack Beta 2.0.0设置Solr 3.6.0.
运行./manage.py build_solr_schemaschema.xml并将其移动到conf目录后,在访问时http://localhost:8983/solr/admin,我收到的错误与此线程中生成的错误完全相同.
org.apache.solr.common.SolrException: No cores were created, please check the logs for errors
java.lang.RuntimeException: Can't find resource 'stopwords_en.txt' in classpath or 'solr/./conf/', cwd=/home/randall/startupsearch_live/apache-solr-3.6.0/example
在线程的底部,用户提到必须编辑schema.xml以匹配stopwords_en.txt到/ example/solr/conf /目录,我通过符号链接和编辑stopwords.txt的所有实例来完成.到生成的schema.xml文件中的/solr/conf/stopwords_en.txt.但是,同样的错误仍然存在,输出略有不同:
java.lang.RuntimeException: Can't find resource '/solr/conf/stopwords_en.txt' in classpath or 'solr/./conf/', cwd=/home/randall/startupsearch_live/apache-solr-3.6.0/example
我必须编辑哪个文件才能解决此问题?
datetime.datetime.now()我的原生时区UTC-8 的输出输出.我想将其转换为适当的时间戳,其tzinfo为UTC.
from datetime import datetime, tzinfo
x = datetime.now()
x = x.replace(tzinfo=UTC)
Run Code Online (Sandbox Code Playgroud)
^ outputs NameError:未定义名称"UTC"
x.replace(tzinfo=<UTC>) 输出SyntaxError:语法无效
x.replace(tzinfo='UTC') 输出TypeError:tzinfo参数必须是None或tzinfo子类,而不是'str'类型
用于完成我的示例的正确语法是什么?
我有以下方式设置argparse参数:
parser = argparse.ArgumentParser(description='foobar')
parser.add_argument('url', metavar='URL')
parser.add_argument('-k', dest='kindle_type', default='kindle3')
parser.add_argument('-n', dest='gallery_name', default='Gallery')
parser.add_argument('-d', dest='dropbox_dir')
args = parser.parse_args()
print parser.parse_args(['imgur_url', '-k'])
Run Code Online (Sandbox Code Playgroud)
但是,当我运行时script.py -k kindledx http://url.com,我收到以下错误:gallery2kindle.py: error: argument -k: expected one argument
当我在'-k'标志后使用'kindledx'时,不是一个被称为争论的论点吗?
我有一个Django项目设置,S3作为静态文件主机.
settings.py
AWS_STORAGE_BUCKET_NAME = 'project-1'
conn = boto.connect_s3()
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://project-1.s3.amazonaws.com/'
STATIC_URL = S3_URL
Run Code Online (Sandbox Code Playgroud)
然后我使用模板标记在模板中引用静态文件,如下所示:
<script src="{% static 'js/jquery.payment.js' %}"></script>
Run Code Online (Sandbox Code Playgroud)
这个正确呈现在浏览器中,但URL对他们来说,其他3个参数Signature,Expires和AWSAccessKeyId.后两者对文件没有任何影响,但使用呈现的Signature值访问文件会导致InvalidAccessKeyId错误,并显示消息"您提供的AWS访问密钥ID在我们的记录中不存在".
手动删除Signature参数让我可以正常访问该文件.拿走所有三个参数都很好.取消后两个参数中的任何一个都会导致错误:"查询字符串身份验证需要Signature,Expires和AWSAccessKeyId参数".
亚马逊的S3文档显示,查询字符串身份验证用于允许您访问通常需要身份验证的文件,并且该Expires参数不像我认为的那样与缓存相关.由于看起来这些文件不需要任何身份验证(即我可以在没有URL参数时访问它们),我需要帮助:
Signature值我正在尝试创建一个自定义ListView适配器(大致基于本教程,但示例很简单,我怀疑你需要看看它).
NewsEntriesAdapter.java
public class NewsEntriesAdapter extends BaseAdapter {
private static ArrayList<NewsEntries> newsEntriesArrayList;
private final LayoutInflater mInflater;
public NewsEntriesAdapter(Context context, ArrayList<NewsEntries> entries) {
newsEntriesArrayList = entries;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return newsEntriesArrayList.size();
}
@Override
public Object getItem(int position) {
return newsEntriesArrayList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.assignment_list_row_view,
null);
holder = …Run Code Online (Sandbox Code Playgroud) 使用Django Haystack设置搜索页面需要输入他们的URLconf片段url(r'^search/', include('haystack.urls')).但是,这意味着(至少从我对Django/MVC的基本理解),没有简单的方法来传递额外的上下文(即额外的字典键/值)来呈现到页面上.
特别是,我想自定义一个搜索字段来镜像从GET请求传递到页面的变量:
<form method="get" action=".">
<input type="text" name="q" value="">
<!-- result html here -->
</form>
Run Code Online (Sandbox Code Playgroud)
假设参数?q=twitter作为GET请求的一部分附加到URL; 我想让value选择器等于twitter.如果我控制了视图,我可能会这样做:
if request.method == 'GET':
q = request.GET['q']
return render(request, 'template.html', {'q': q})
Run Code Online (Sandbox Code Playgroud)
然后将其q用作valueHTML中选择器的值<input>.
除了编辑Haystack源之外,有没有办法以简单的方式完成这个任务?
我已将所有函数包装在一个立即调用的函数表达式中,如下所示:
(function(){
"use strict";
function toggleComment(parentCommentID) {
$("form#" + parentCommentID).toggle();
}
function scrollBottom() {
window.scrollTo(0, document.body.scrollHeight);
}
})();
Run Code Online (Sandbox Code Playgroud)
但是,在通过链接调用其中一个函数时:
<a href="javascript:void(0)" onclick="toggleComment(159); return false;">Reply</a>
Run Code Online (Sandbox Code Playgroud)
Chrome控制台输出Uncaught ReferenceError: toggleComment is not defined.我是否错误地认为应该立即调用一个立即调用的函数表达式,因此toggleComment应该调用它?我应该以不同方式调用该功能吗
我想让nginx和gunicorn一起工作.我有一个/project/static/静态文件所在的目录./project/livestatic/使用显示的settings.py配置将这些文件收集到目录中:
STATIC_ROOT = '/project/livestatic'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/project/static',
)
Run Code Online (Sandbox Code Playgroud)
我正在使用以下nginx配置:
worker_processes 1;
user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /tmp/nginx.access.log combined;
sendfile on;
upstream app_server {
server 127.0.0.1 fail_timeout=0;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name domain.org;
keepalive_timeout 5;
# path for static files
location /static/ {
autoindex on;
root /var/www/startupsearch_live/livestatic/;
}
location / { …Run Code Online (Sandbox Code Playgroud) django ×6
android ×3
python ×3
amazon-s3 ×1
argparse ×1
datetime ×1
django-forms ×1
get ×1
gradle ×1
gunicorn ×1
javascript ×1
listview ×1
nginx ×1
post ×1
solr ×1
static-files ×1
stop-words ×1
templates ×1
translation ×1