尝试单击“新颜色集”按钮时出现此错误:
NoReverseMatch at /colorsets/new/
Reverse for 'user_logout' not found. 'user_logout' is not a valid view function or pattern name.
Run Code Online (Sandbox Code Playgroud)
我已经通过 StackOverflow 和其他网站上的其他地方进行了广泛的查看,但似乎无法找到问题所在。到目前为止,我可以说我的所有代码都是正确的,但显然存在问题。
基本.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Colors</title>
<meta name"viewport" content="width=device-width, initial-scale=1">
<meta charset="uft-8">
<link rel="shortcut icon" href="/images/favicon.ico">
<link rel="stylesheet" href="/style.css">
</head>
<body>
<nav>
<div class="container">
<a class="btn" href="{% url 'index' %}">Home</a>
{% if user.is_authenticated %}
<a class="btn" href="{% url 'colorsets:new_color' %}">New Color Set</a>
<a class="btn" href="{% url 'accounts:user_logout' %}">Logout</a>
{% else %}
<a class="btn" href="{% url 'accounts:user_login' %}">Login</a> …
Run Code Online (Sandbox Code Playgroud) 也许我没有正确设置它?在过去的3个小时中,我一直在查看代码,因此有可能我正在寻找一些东西。无论哪种方式,我都将这个h3放在div中,并且希望将其水平和垂直居中放置,但是只能使用水平。
<div class="col-md-4">
<div class="align-items-center" style="background-image:url({{ uni.u_homepage_pic.url }}); background-repeat:no-repeat; width: 350px; height: 225px;">
<h3 class="text-center" style="color:#ffffff;">{{ uni.u_name }</h3>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
更新:使用Bootstrap V4
我有一个完整的 Sprite Kit 游戏,它本身很可靠,但是我真的很想将实时多人游戏功能融入其中。唯一的问题是我找不到任何教程来说明如何做到这一点(raywenderlich.com 有一个,但它是使用 Objective-C 的,而我的游戏是用 Swift 编写的)。
我已经通读了苹果的文档,但是,它实际上只是涵盖了正在发生的事情的逻辑,并列出了所使用的部分,而不是实际展示如何实现代码。
我想知道是否有人可以帮助我如何实际实施代码。从我通过搜索可以看出,这是一个非常受欢迎的主题,但没有任何关于使用 swift 的教程。
我试图理解这两个 char 声明之间的内在区别:
char* str1;
char str2[10];
Run Code Online (Sandbox Code Playgroud)
我知道 usingchar*
给出了指向 中第一个字符的指针str1
,而char[10]
结果是一个长度为 10 个字节的数组(因为char
是一个字节......我记得在某些编码中它可以更多,但我们假设一个字节把事情简单化)。
我的问题是,当实际为它们赋值时,数据显然必须存储在某个地方,并且在char[10]
我们预先告诉编译器分配十个字节的情况下,而在char*
我们实际上只是说分配一个指向单字节。但是如果我们分配的字符串str1
超过一个字节会发生什么,它是如何分配的呢?还需要做多少工作才能适当分配?另外,如果我们想重新分配str1
比之前分配的更长的值,会发生什么,如何分配?
由于处理 时从编译器的角度来看存在不确定性,当我提前知道长度或想要限制开始时的长度时,char pointers
使用 a 是否更有效?char array
我知道您应该在每个应用程序文件夹中都有一个模板文件夹,如何进一步澄清两个问题。1,我是否应该有2个相同的base.html文件(每个应用程序一个)?似乎正在创建比需要的文件更多的文件……2.静态和媒体文件夹又如何?我是否应该每个都有两个,还是应该在项目和应用文件夹级别?
如果应该在每个应用程序文件夹中都有一个静态文件夹,那么我是否有两个CSS文件?我觉得这没有任何意义,因为CSS可以覆盖应用程序之间重叠的内容。
我也想知道是否按照我目前的方式设置它会影响任何事情,或者“最佳实践”是否更多,仅仅是因为您正在与多个人一起工作的项目(我不是,所以我应该注意吗?)
这是我当前的结构:
/evverest/
/evverest/
/feed/
/users/
/blog/
/templates/
/base/
/feed/
/users/
/static/
/css/
/media/
/post_pics/
/profile_pics/
Run Code Online (Sandbox Code Playgroud) 所以我刚刚设置了我的数字海洋液滴(服务器)并且一直在努力让这个网站工作,但是我在错误之后遇到了错误.我终于得到了加载登录页面的网站(这应该是什么),但是当我登录时,我得到一个Argon2 Pass Hasher无法加载的错误.我真的不知道问题是什么,因为在开发过程中一切都很完美.
这是错误:
ValueError at /accounts/login/
Couldn't load 'Argon2PasswordHasher' algorithm library: No module named argon2
Run Code Online (Sandbox Code Playgroud)
这是我的设置:
"""
Django settings for django_project project.
Generated by 'django-admin startproject' using Django 1.8.7.
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__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
MEDIA_DIR = os.path.join(BASE_DIR, 'media')
# Quick-start development settings - unsuitable for …
Run Code Online (Sandbox Code Playgroud) 我有一个对象列表,每个对象都有一个图标属性,如下所示:
List<Map<String, String>> _categories = [
{
'name': 'Sports',
'icon': 'directions_run',
},
{
'name': 'Politics',
'icon': 'gavel',
},
{
'name': 'Science',
'icon': 'wb_sunny',
},
];
Run Code Online (Sandbox Code Playgroud)
然后我在 ListView.builder() 小部件中使用了一个小部件。目前,我正在显示一个静态选择的图标,以与列表中的文本一起显示。我的问题是如何使用对象中的 icon 属性来动态选择为每个单独的列表项显示的图标?
Widget _buildCategoryCards(BuildContext context, int index) {
return Container(
padding: EdgeInsets.symmetric(vertical: 5.0),
child: Card(
child: Container(
padding: EdgeInsets.all(15.0),
child: Row(
children: <Widget>[
Icon(Icons.directions_run),
SizedBox(width: 20.0),
Text(_categories[index]['name']),
],
),
),
),
);
}
Run Code Online (Sandbox Code Playgroud) 我在状态类中有一个调用 setState 的方法,但是无论何时调用它都会抛出 aUnsupportedError (Unsupported operation: read-only)
并且不提供其他信息。你能看出我的代码有什么问题可以让它这样做吗?我似乎这应该很简单......
Future _uploadFile(imageFile, imageFilename, String imageNumber) async {
_user = await DBProvider.db.getUser();
final FirebaseStorage _storage = FirebaseStorage(storageBucket: 'gs://circle-fc687.appspot.com');
StorageReference _storageRef = _storage.ref().child('users').child('${_user['uid']}').child('$imageFilename');
final Directory systemTempDir = Directory.systemTemp;
final File file = await File('${systemTempDir.path}/$imageFile').create();
StorageUploadTask _uploadTask = _storageRef.putFile(file);
await _uploadTask.onComplete;
print('Upload complete');
String downloadLink = await _storageRef.getDownloadURL();
setState(() {
_user['imageOne'] = downloadLink;
});
}
Run Code Online (Sandbox Code Playgroud)
编辑
调用setState
不是问题,因为尝试_user['imageOne'] = downloadLink;
从该方法中更新 Map 属性也会导致相同的错误。这个变量不是 final 或类似的东西,只是Map<String, dynamic>
我很确定我的所有设置都正确,或者至少非常接近正确。但是,要么notifyLister()
,我consumer
的不工作,要么两者兼而有之。
我的UserModel
设置是这样的
...
class UserModel with ChangeNotifier {
Map<dynamic, dynamic> _user;
Map get user {
return _user;
}
void setUser(user) {
_user = user;
notifyListeners();
}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序设置是这样的 main.dart
...
void main() {
runApp(ChangeNotifierProvider(
builder: (context) => UserModel(),
child: MyApp()
),
);
}
Run Code Online (Sandbox Code Playgroud)
接下来,我有一个按钮,调用setUser
的方法UserModel
...
UserModel().setUser(user);
...
Run Code Online (Sandbox Code Playgroud)
最后,我Consumer
在构建方法的列中嵌套了一个app.dart
....
Consumer<UserModel>(
builder: (context, user, child) {
return user.user == null ? Text(
'NULL ${user.user}',
style: TextStyle(fontSize: 28),
) : …
Run Code Online (Sandbox Code Playgroud) 每个用户都有一个模型字段,用于跟踪我们网站上的分数.每次用户做一些我想要添加或减去他们的分数.
在这种特殊情况下,我想在我的网站上发布帖子时更改用户分数.我可以访问用户的分数,但不能修改它.这是我到目前为止:
def createPost(request):
user = UserProfile.objects.get(user=request.user)
current_score = user.user_score
if request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
...
user.user_score = current_score - 1
...
else:
form = PostForm()
return render(request,'feed/userpost_form.html',{'form':form})
Run Code Online (Sandbox Code Playgroud)
我没有收到任何错误,发布帖子工作正常,只是没有修改用户的分数.另外,我正在使用Django 1.11
我正在尝试使用 Flutter 团队提供的 Share 包。我尝试实现该包,当它不起作用时,我尝试直接复制和粘贴他们的代码,但同样出现错误。不幸的是,这个错误不是很有帮助,错误的描述说“我们需要更好地解释这个”。有任何想法吗?
我的代码:
FlatButton(
child: Text(
'Share',
style: TextStyle(
color: Color.fromRGBO(245, 93, 62, 1.0)),
),
color: Colors.grey[100],
onPressed: () {
final RenderBox box = context.findRenderObject();
Share.share('Hello this is a test',
sharePositionOrigin:
box.localToGlobal(Offset.zero) &
box.size);
},
),
Run Code Online (Sandbox Code Playgroud)
错误:
flutter: The following assertion was thrown while handling a gesture:
flutter: type 'RenderSliverList' is not a subtype of type 'RenderBox'
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more …
Run Code Online (Sandbox Code Playgroud) 所以我试图在学习 Go 的同时了解并行计算的工作原理。我理解并发和并行之间的区别,但是,我有点困惑的是 Go(或操作系统)如何确定某些内容应该并行执行......
在编写代码时我必须做一些事情,还是所有事情都由调度程序处理?
在下面的示例中,我有两个函数使用 go 关键字在单独的 Go 例程中运行。因为默认的 GOMAXPROCS 是您机器上可用的处理器数量(并且我也明确设置了它),所以我希望这两个函数同时运行,因此输出将是按特定顺序排列的数字的混合 - 并且此外,每次运行的输出都会不同。然而,这种情况并非如此。相反,它们一个接一个地运行,更令人困惑的是,函数二在函数一之前运行。
代码:
func main() {
runtime.GOMAXPROCS(6)
var wg sync.WaitGroup
wg.Add(2)
fmt.Println("Starting")
go func() {
defer wg.Done()
for smallNum := 0; smallNum < 20; smallNum++ {
fmt.Printf("%v ", smallNum)
}
}()
go func() {
defer wg.Done()
for bigNum := 100; bigNum > 80; bigNum-- {
fmt.Printf("%v ", bigNum)
}
}()
fmt.Println("Waiting to finish")
wg.Wait()
fmt.Println("\nFinished, Now terminating")
}
Run Code Online (Sandbox Code Playgroud)
输出:
go run main.go
Starting
Waiting to finish
100 99 …
Run Code Online (Sandbox Code Playgroud)