我正在尝试开发一个应用程序,其中实体通过其键Student添加到Class实体.所以在课堂上,我可以List通过他们的键可以识别一个学生,可以是Integer或String.But我不知道如何做到这一点.(请忍受我,这是我的第一个使用Python的项目)这里是我的代码:
import webapp2
from webapp2_extras import json
from google.appengine.ext import ndb
registrationPage = """
<html>
<head><title>Student Registration</title><head>
<body>
<h1>Student Registration</h1>
<form action="/" method="post">
<table border="1">
<tr><td>Srudent's BannerId</td><td><input type="number" size="6" name="banner_id"/></
td></tr>
<tr><td>Student's Name</td><td><input type="text" size="50" name="name"/></td></tr>
<tr><td><input type="submit" name="submit" value="Register Student"/></td></tr>
</table>
</form>
</body>
</html>
"""
class MathClass (ndb.Model):
class_Id = ndb.IntegerProperty(required=True)
professor_name = ndb.StringProperty(required=True)
number_of_students = ndb.IntegerProperty()
students = ndb.KeyProperty(repeated=True)
# A Class can return its data in JSON format
def toJSON(self):
jsonData …Run Code Online (Sandbox Code Playgroud) 我有一个类,Student有这个构造函数.
public Student(String name, int age, Map<String, Integer> grades) {
this.setName(name);
this.setAge(age);
this.setGrades(grades);
}
Run Code Online (Sandbox Code Playgroud)
在创建Student对象时,如何在构造函数中传递Map参数?
我们正在寻找的是类似的东西:
List<Student> roster = new ArrayList<>();
roster.add(new Student("Ann Droid", 145, Arrays.asList(96, 78)));
Run Code Online (Sandbox Code Playgroud)
如果我有这个构造函数:
public Student(String name, int age, List<Integer> grades) {
this.setName(name);
this.setAge(age);
this.setGrades(grades);
}
Run Code Online (Sandbox Code Playgroud) 我有一个案例,我想使用单选按钮作为我的查询选项,这样我就可以根据所选的单选按钮获得正确的查询集.我无法找到一种方法来获取表单中选定的单选按钮值.关于使用表单类有很多信息.简单的html表单怎么样?形式的一部分是:
<label for="house-all-id">All</label>
<input type="radio" id="house-all-id" name="h-type" value="0"/>
<label for="house-orp-id">Just case one</label>
<input type="radio" id="house-orp-id" name="h-type" value="1"/>
<label for="house-inm-id">Just case two</label>
<input type="radio" id="house-inm-id" name="h-type" value="2"/>
Run Code Online (Sandbox Code Playgroud)
这些单选按钮是另一个小部件的一部分,以帮助我获得正确的QuerySet.在视图中:
h_type = request.POST.get('h_type')
Run Code Online (Sandbox Code Playgroud)
这将返回一个非类型对象.如何获得所选单选按钮的值?
我正在使用此代码检查设备是否在应用程序加载时处于联机状态.
public boolean isOnline()
{
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
return (networkInfo != null && networkInfo.isConnected());
}
Run Code Online (Sandbox Code Playgroud)
但即使它已关闭计算机Wifi进行测试,这总是会返回true.这个功能只是测试连接或实际连接的能力吗?
谢谢!
我试图在我的应用程序中使用Facebook登录Android Studio中的Facebook库.
在关注如何在Android Studio 0.6.1上导入该库的9个教程之后,在点击清洁项目之前一切顺利(在上一个教程中),点击它之后我收到此错误:
*C:\Users\Demetria\AndroidStudioProjects\Test\libreries\facebook\src\com\facebook\FacebookA ppLinkResolver.java
Error:(21, 13) error: package bolts does not exist
Error:(37, 49) error: cannot find symbol class AppLinkResolver
Error:(57, 12) error: cannot find symbol class Task
Error:(63, 42) error: cannot find symbol class Continuation
Error:(105, 83) error: cannot find symbol variable Task
Error:(192, 27) error: package AppLink does not exist*
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?
提前致谢.
我是 Django 的新手。
我在终端中遇到的错误是
“获取静态/css/bootstrap.min.css HTTP/1.1”404 1676
我的工作目录是这样的:
*Project
**App
**blog
**static
**db.sqlite3
**manage.py
Run Code Online (Sandbox Code Playgroud)
在我的主页上,我尝试了两件事
a) 没有静态标签即href="static/css/bootstrap.min.css"
b) 使用静态标签,即 **href={% static "static/css/bootstrap.min.css" %}"
我什至添加了
TEMPLATE_DIRS=('/HOME/AA/Project/blog/templates ',)
Run Code Online (Sandbox Code Playgroud)
我应该如何修复这个 GET 错误并正确呈现我的引导文件?我什至将这些文件添加为静态文件。
这是我的settings.py
Django settings for luckdrum project.
Generated by 'django-admin startproject' using Django 1.8.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start …Run Code Online (Sandbox Code Playgroud) 根据Oracle的定义,
有时,您希望拥有所有对象共有的变量.这是通过静态修改器完成的.在声明中具有static修饰符的字段称为静态字段或类变量.它们与类相关联,而不是与任何对象相关联.该类的每个实例共享一个类变量,该变量位于内存中的一个固定位置.
通过这个定义,可以安全地推断出一个静态变量属于该类,并且不应该被类的任何对象访问以进行修改.因为所有对象都共享它.
所以来自同一定义的这一行有点令人困惑:
任何对象都可以改变类变量的值......
所以我尝试了这个代码并打印出45(尽管我收到警告说"通过实例引用访问静态成员"):
public class Main {
static int value = 8;
public static void main(String[] args) {
// write your code here
Main main = new Main();
main.value = 45;
System.out.println(value);
}
}
Run Code Online (Sandbox Code Playgroud)
如果这是一个Student类,并且我有一个静态变量numberOfStudents,为什么要允许该类的一个对象更改此类变量的值?
刚刚开始使用这项服务,文档有点令人困惑.我创建了一个Space使用照片库模板.在这个空间中,我有类型图像,作者和照片库的条目.我的问题是,如何检索图像以便在我的Android应用程序中显示?
为了与之交互Contentful Delivery API,我知道我必须使用一个CDAClient对象和CDAEntry对象来尝试获取.
我已经在onCreate()我的Fragment类的方法中定义了这个,如下所示:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
client = CDAClient.builder()
.setSpace("id-of-the-space-am-accessing")
.setToken("the-access-token")
.build();
entry = client.fetch(CDAEntry.class).one("the id of the image I want to retrieve");
}
Run Code Online (Sandbox Code Playgroud)
在onCreateView()方法中,我试图像这样查看结果:
Log.e(TAG, "Result: " + entry.toString());
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我在Logcat中得到了这个:
E/NEWS ACTIVITY? Result: CDAEntry{id='2YhtjbebgscIwO2keYEa4O'}
Run Code Online (Sandbox Code Playgroud)
此id匹配我传递给的图像的id client.fetch(CDAEntry.class).one()
显然我正在获取图像,但我该如何显示它?
如何在中提供用户定义的键值push(),而不是通过push创建的唯一值?
这是当前正在执行的操作:
User user = new User(Editname.getText().toString(),
Editpid.getText().toString(),Editsem.getText().toString());
mRef.child("users").push().setValue(user);
Run Code Online (Sandbox Code Playgroud) MainActivity中包含的导航抽屉导航到多个片段.在这些Fragment类的onCreate方法中,我试图onAuthStateChanged获取当前用户:
FirebaseAuth.AuthStateListener mAuthListener;
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
user = firebaseAuth.getCurrentUser();
if (user != null ) {
Log.e(TAG, "onAuthStateChanged:signed_in" + user.getUid());
} else { //user is not logged in
Log.e(TAG, "onAuthStateChanged:signed_out");
}
}
};
}
Run Code Online (Sandbox Code Playgroud)
但从onAuthStateChanged未被称为.类似的代码MainActivity工作得很好.我试过在片段的方法onCreateView()和调用onResume()方法中调用此代码,但没有任何反应.为了解决这个问题并获得当前用户,我在MainActivity中创建了一个方法:
public FirebaseUser getFirebaseUser() {
return user;
}
Run Code Online (Sandbox Code Playgroud)
然后通过执行以下操作调用Fragment类中的方法:
FirebaseUser user = ((MainActivity) getActivity()).getFirebaseUser();
if (user != null ) {
Log.e(TAG, …Run Code Online (Sandbox Code Playgroud) android ×5
django ×2
firebase ×2
java ×2
contentful ×1
django-views ×1
facebook ×1
forms ×1
html ×1
python ×1
python-3.x ×1