小编Kha*_*inn的帖子

Django序列化器Imagefield获取完整的URL

我是Django的初学者,目前,我可以构建这样的模型.

在此输入图像描述

models.py

class Car(models.Model):
    name = models.CharField(max_length=255)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    photo = models.ImageField(upload_to='cars')
Run Code Online (Sandbox Code Playgroud)

serializers.py

class CarSerializer(serializers.ModelSerializer):
    class Meta:
        model = Car
        fields = ('id','name','price', 'photo') 
Run Code Online (Sandbox Code Playgroud)

views.py

class CarView(APIView):
    permission_classes = ()
    def get(self, request):
        car = Car.objects.all()
        serializer = CarSerializer(car)
        return Response(serializer.data)
Run Code Online (Sandbox Code Playgroud)

对于照片,它不会显示完整的网址.如何显示完整的URL?

python django django-rest-framework

29
推荐指数
4
解决办法
2万
查看次数

ios 9 iphone 6S播放触觉反馈或振动

用户强行触摸后,我想像默认行为一样振动手机.

它是触觉吗?如果是这样,我该怎么办?

ios9 3dtouch

19
推荐指数
4
解决办法
7582
查看次数

php图像文件上传并转换为base64而不保存图像

我知道如何上传图像文件并使用以下代码保存到其他位置.但是,我需要这样做,用户上传图像并自动转换为base64而不保存我的位置中的图像.我应该怎么做?

<?php
//print_r($_FILES);
if(isset($_FILES['image']))
{
    $errors=array();
    $allowed_ext= array('jpg','jpeg','png','gif');
    $file_name =$_FILES['image']['name'];
 //   $file_name =$_FILES['image']['tmp_name'];
    $file_ext = strtolower( end(explode('.',$file_name)));


    $file_size=$_FILES['image']['size'];
    $file_tmp= $_FILES['image']['tmp_name'];
    echo $file_tmp;echo "<br>";

    $type = pathinfo($file_tmp, PATHINFO_EXTENSION);
    $data = file_get_contents($file_ext);
    $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
    echo "Base64 is ".$base64;



    if(in_array($file_ext,$allowed_ext) === false)
    {
        $errors[]='Extension not allowed';
    }

    if($file_size > 2097152)
    {
        $errors[]= 'File size must be under 2mb';

    }
    if(empty($errors))
    {
       if( move_uploaded_file($file_tmp, 'images/'.$file_name));
       {
        echo 'File uploaded';
       }
    }
    else
    {
        foreach($errors as $error)
        { …
Run Code Online (Sandbox Code Playgroud)

php upload base64 image

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

ios 8自定义键盘在设置页面中更改语言

我正在编写自定义键盘.当我在设置中添加键盘时,我看到了这样的.它显示英语.

是否可以将"英语"改为其他?是在plist?或者我可以在哪里更改?

在此输入图像描述

ios ios8 ios-app-extension custom-keyboard

11
推荐指数
2
解决办法
1595
查看次数

NSLocalizedString不适用于某些单词

我有英文,日文,韩文Localizable.strings文件.我无法从韩国文件中加载一些单词.我也检查过拼写,大写字母或小写字母.它是正确的.我已清理项目,重置模拟器并删除设备上的应用程序.对某些词语不起作用.我可以知道该怎么办吗?

localizable.strings ios

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

iOS 9 Parse(v 1.8.5)Facebook(v 4.6)登录崩溃FBSDKInternalUtility checkRegisteredCanOpenURLScheme

我正在使用Swift 2使用解析iOS 9进行简单的登录.我使用解析时的ParseFacebookUtilsV4.framework.

我从这个链接完全遵循iOS 9的说明.

https://developers.facebook.com/docs/ios/ios9

另外,我正在使用Parse(v 1.8.5)Facebook(v 4.6).但是,当我尝试这样登录时,

    let permissions = ["user_about_me", "user_relationships", "user_birthday", "user_location"]

    PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, block: { (user: PFUser?, error: NSError?) -> Void in //switched ! to ?
        if user == nil {
            NSLog("Uh oh. The user cancelled the Facebook login.") }
        else if user!.isNew
        { //inserted !
            NSLog("User signed up and logged in through Facebook!")
        }
        else {
            NSLog("%@", error?.localizedDescription as String!)
            NSLog("User logged in through Facebook! \(user!.username)")
        } })
Run Code Online (Sandbox Code Playgroud)

它崩溃了.我也无法追踪它崩溃的原因和原因.我该如何解决?

+[FBSDKInternalUtility checkRegisteredCanOpenURLScheme:]:
0x10014ec04 <+0>:   stp    x22, …
Run Code Online (Sandbox Code Playgroud)

facebook ios facebook-login parse-platform swift2

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

React Native:更改 Paper Button 中的文本颜色

我对 React Native 比较陌生。

我可以轻松地显示按钮(带有阴影等),如下所示。

 <Button
  mode="contained"
  color={'#f08e25'}
  contentStyle={{ height: 44 }}
  onPress={this.onPressSubmit}
  theme={theme} >SUBMIT </Button>
Run Code Online (Sandbox Code Playgroud)

我也参考了这个文档。

https://callstack.github.io/react-native-paper/button.html#contentStyle

问题是如果模式是“包含”,我无法更改文本颜色。我在 contentStyle 或 theme 中尝试过,但它不起作用。如果模式是“包含”,我该如何更改文本颜色?

react-native react-native-paper

8
推荐指数
2
解决办法
2万
查看次数

带有substringWithRange的Swift 2.0字符串

我试图从String得到第一个char.它应该很容易,但我不能在Swift 2.0中使用(使用Xcode beta 6).

在Swift编程语言中获取字符串的第n个字符

我也试过那种方法.它使用扩展但我无法使用该方法检索.我可以知道该怎么办吗?

string ios swift2

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

检测用户点击本地通知

我会定期显示我的本地通知.

UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:@"Test test"];
[notification setUserInfo:@{@"test": @"test"}];
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
Run Code Online (Sandbox Code Playgroud)

我需要检测回来的通知,我打算在这里写.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Run Code Online (Sandbox Code Playgroud)

无论用户点击通知还是自动呼叫前台,它总是调用该功能.

所以,我分开使用它.

if (application.applicationState == UIApplicationStateActive)
Run Code Online (Sandbox Code Playgroud)

当我显示通知中心时,它变为InActive.但是,它仍然调用didReceiveLocalNotification.我无法区分用户是否点击通知中心的通知或是因为我的定期发布通知.

我怎么才能真正知道我在didReceiveLocalNotification中点击通知(来自InActive State或Background State)?

ios uilocalnotification

7
推荐指数
2
解决办法
7724
查看次数

自定义UIApplicationShortcutIcon

是否可以创建自定义UIApplicationShortcutIcon?或者只有苹果给出的那个?

在此输入图像描述

xcode ios ios9 3dtouch

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