小编Ahm*_*gdi的帖子

Django对于基数为10的int()无效的文字:'??????? ???????" 当我尝试迁移

我正在尝试在添加到我的项目中的新应用程序中创建一个新表格.. makemigrations工作得很好但是migrate不起作用..这是我的模型

博客/ models.py

from django.db import models

# Create your models here.
from fostania_web_app.models import UserModel


class Tag(models.Model):
    tag_name = models.CharField(max_length=250)

    def __str__(self):
        return self.tag_name


class BlogPost(models.Model):
    post_title = models.CharField(max_length=250)
    post_message = models.CharField(max_length=2000)
    post_author = models.ForeignKey(UserModel, on_delete=models.PROTECT)
    post_image = models.ImageField(upload_to='documents/%Y/%m/%d', null=False, blank=False)
    post_tag = models.ForeignKey(Tag, on_delete=models.PROTECT)
    post_created_at = models.DateTimeField(auto_now=True)
Run Code Online (Sandbox Code Playgroud)

当我尝试做python manage.py migrate我得到这个错误

invalid literal for int() with base 10: '??????? ???????'

UserModel是在同一项目中的另一个应用程序中创建的,这就是我使用该语句的原因from fostania_web_app.models import UserModel

fostania_web_app/models.py

class UserModelManager(BaseUserManager):
    def create_user(self, email, password, …
Run Code Online (Sandbox Code Playgroud)

python django

1
推荐指数
1
解决办法
915
查看次数

ngx-translate 不适用于带有 ionic 4 的设备

我正在尝试ngx-translate与我的Ionic 4项目一起使用,我已经遵循了本指南。它在我的浏览器中运行良好,但是当我在我的 android 设备上构建和测试时它无法转换。

我已经使用npm然后添加到导入中安装了它,创建了函数并将标签添加到我的 HTML 中。

这是我的代码

安装使用:

npm install @ngx-translate/core @ngx-translate/http-loader --save

app.module.ts

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouteReuseStrategy} from '@angular/router';
import {IonicModule, IonicRouteStrategy} from '@ionic/angular';
import {SplashScreen} from '@ionic-native/splash-screen/ngx';
import {StatusBar} from '@ionic-native/status-bar/ngx';
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';
import {CallNumber} from '@ionic-native/call-number/ngx';
import {Camera} from '@ionic-native/camera/ngx';
import { AuthServiceService } from './auth-service.service';
import { IonicStorageModule } from '@ionic/storage';
import { TranslateModule, …
Run Code Online (Sandbox Code Playgroud)

typescript ionic-framework angular ionic4

1
推荐指数
1
解决办法
1881
查看次数

Flutter 中的 Facebook 登录错误:访问令牌错误:{"code":190,"message":"无效的 OAuth 访问令牌。"}],空)

我正在尝试在我的 flutter 应用程序上实现 Facebook Firebase 身份验证,

我已经解决了所有问题并且一切顺利,但是在 Facebook 要求用户提供登录凭据之后。它给了我这个错误:

PlatformException(ERROR_INVALID_CREDENTIAL, The supplied auth credential is malformed or has expired. [ Bad access token: {"code":190,"message":"Invalid OAuth access token."} ], null)
Run Code Online (Sandbox Code Playgroud)

这是我使用的代码:

PlatformException(ERROR_INVALID_CREDENTIAL, The supplied auth credential is malformed or has expired. [ Bad access token: {"code":190,"message":"Invalid OAuth access token."} ], null)
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的软件包 pubspec.yaml

  Future faceBookSignIn() async {
    try{
      var result = await _facebookAuth.logIn(['email']);
      print(result.status.toString());
      if (result.status == FacebookLoginStatus.loggedIn){
        final AuthCredential credential = FacebookAuthProvider.getCredential(accessToken: result.accessToken.toString());
        AuthResult facebookResult = await _auth.signInWithCredential(credential);
        FirebaseUser facebookUser …
Run Code Online (Sandbox Code Playgroud)

android ios firebase firebase-authentication flutter

1
推荐指数
1
解决办法
587
查看次数

在django中使用distinct()和filter()

我正在尝试在 Django 中创建一个查询,该查询调用distinct满足过滤器某些条件(使用)的唯一行(使用filter

\n\n

这是使用的文件:

\n\n

视图.py

\n\n
def cat_details(request, pk):\n    current_user = request.user\n    selected_cat = get_object_or_404(Category, pk=pk)\n    selected_items = ItemIn.objects.all().filter(item_category=selected_cat).values_list(\'item_name\', flat=True).distinct()\n    all_cats = Category.objects.all()\n    cat_count = all_cats.count()\n    item_count = ItemIn.objects.values_list(\'item_name\', flat=True).distinct().count()  # returns a list of tuples..\n    #all_units = Item.objects.aggregate(Sum(\'item_quantity\'))[\'item_quantity__sum\']\n    context = {\n        #\'all_units\': all_units,\n        \'item_count\': item_count,\n        \'cat_count\': cat_count,\n        \'selected_items\': selected_items,\n        \'selected_cat\': selected_cat,\n        \'current_user\': current_user,\n    }\n\n    return render(request, \'townoftech_warehouse/cat_details.html\', context)\n
Run Code Online (Sandbox Code Playgroud)\n\n

调用的变量selected_items就是问题所在!

\n\n

这是我如何使用这个视图函数

\n\n

超文本标记语言

\n\n
{% extends \'townoftech_warehouse/base.html\' %}\n    {% block …
Run Code Online (Sandbox Code Playgroud)

python django

0
推荐指数
1
解决办法
3万
查看次数

当我尝试在Django中使用DeleteView时,'str'对象不可调用

这是我的文件

urls.py我为删除过程创建的URL路径

path('dress/<int:pk>/delete', views.DressDelete.as_view(), name="dress_delete"),
path('dress/delete/confirm', views.dress_delete_confirm, name="dress_delete_confirm"),
Run Code Online (Sandbox Code Playgroud)

views.py,其中我创建了删除视图以及将在删除完成后显示的视图以通知用户

from django.urls import reverse_lazy
from django.views.generic import DeleteView

class DressDelete (DeleteView):
        model = Item
        success_url = reverse_lazy('dress_delete_confirm')

    @login_required
    def dress_delete_confirm(request):
        return render(request, 'fostania_web_app/dress_delete_confirm.html')
Run Code Online (Sandbox Code Playgroud)

models.py哪里是我试图从删除表:

class Item(models.Model):
    # custom validators
    alphanumeric = RegexValidator(r'^[0-9a-zA-Z]*$', 'Only alphanumeric characters are allowed.')

    # fields
    dress_name = models.ForeignKey(Name, on_delete='DO_NOTHING', blank=False, verbose_name='??? ???????',)
    dress_rate = models.ForeignKey(Rate, on_delete='DO_NOTHING', blank=False, verbose_name='????? ???????',)
    dress_size = models.ForeignKey(Size, on_delete='DO_NOTHING', verbose_name='???? ???????', blank=False)
    dress_color = models.CharField(max_length=50, verbose_name='??? ???????', blank=False)
    dress_image1 …
Run Code Online (Sandbox Code Playgroud)

python django

0
推荐指数
1
解决办法
382
查看次数

图标没有出现在 MaterialButton android studio 中

我正在添加MaterialButton到我的 android 项目,它只显示文本而不是文本和图标,这是我的代码:

    <com.google.android.material.button.MaterialButton
        android:id="@+id/homeBtn1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="8dp"
        android:gravity="center"
        android:textAllCaps="true"
        android:textColor="#F8F8F8"
        android:background="#3F51B5"
        android:text="@string/findTrans"
        app:icon="@drawable/white_bus_icon"
        app:iconGravity="textStart"
        app:iconTint="@null"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView2"
         />
Run Code Online (Sandbox Code Playgroud)

按钮的外观如下:

在此输入图像描述

android material-components-android

0
推荐指数
1
解决办法
2439
查看次数

如何添加包含斜杠的动态 URL 部分

URL我在Django 项目中使用动态部分,例如<str:item_code>,有时 str 包含斜杠/,这会导致未找到错误。

我的 URL 模式如下所示:

    path('find/the/item/<str:item_description>/', views.find_the_item, name="find_the_item"),
Run Code Online (Sandbox Code Playgroud)

有没有办法强制 url 忽略这<str:item_description>部分内的所有斜杠?

python django url

0
推荐指数
1
解决办法
240
查看次数