小编And*_*pka的帖子

Django-Rest-Framework AssertionError HTTPresponse预期

当我使用curl在终端上执行以下命令时

curl -X POST http://myuser:mypassword@myweb.com:8000/call/make-call/ -d "tutor=1&billed=1"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

AssertionError at/call/make-call /期望a Response, HttpResponse或者HttpStreamingResponse从视图返回,但是收到了<type 'NoneType'>

我的views.py是

@api_view(['GET', 'POST'])
def startCall(request):

    if request.method == 'POST':

        serializer = startCallSerializer(data=request.DATA)

        if serializer.is_valid():

            serializer.save()

            return Response(serializer.data, status=status.HTTP_201_CREATED)

        else:

            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Run Code Online (Sandbox Code Playgroud)

我的serializer.py是

class startCallSerializer(serializers.ModelSerializer):

    class Meta:
        model = call
        fields = ('tutor', 'billed', 'rate', 'opentok_sessionid')
Run Code Online (Sandbox Code Playgroud)

我的urls.py是

urlpatterns = patterns(
    'api.views',
    url(r'^call/make-call/$','startCall', name='startCall'),
)
Run Code Online (Sandbox Code Playgroud)

python django-rest-framework

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

页面令牌youtube api v3

我想用youtube api v3(/ videos?)进行分页.

My request uri - https://www.googleapis.com/youtube/v3/videos?key={APP_KEY}&part=snippet&maxResults=50&chart=mostPopular&videoCategoryId=10
Run Code Online (Sandbox Code Playgroud)

但作为回应,我没有看到nextPageToken场.

如果我发送maxResult49中设置的字段(不像第一次请求那样50).作为回应,我可以nextPageToken在搜索中找到项目的字段和计数 - 200.但是,当我发送第二部分搜索的新请求时 - 作为响应,我只有15个项目(必须是49个)并且只有nextPageToken字段previousPageToken.

谢谢.

youtube youtube-api

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

在UWP中保持ListView.HeaderTemplate可见/静态/粘性

我需要保持HeaderTemplate一个的ListView可见在任何时候,但我不知道该怎么设置,还是什么的一部分ListView的模板更改为做到这一点.

我目前所拥有的是ListView当向下滚动项目时导致标题滚动到顶部.

ListView即使滚动浏览ListView项目,如何保持可见的标题"行" ?

这是我的XAML:

<ListView x:Name="permitResults"
          Grid.Row="1"
          AutomationProperties.AutomationId="PermitResults"
          AutomationProperties.Name="Permit Search Results"
          ItemsSource="{Binding Source={StaticResource ResultsSource}}" 
          ItemClick="permitResults_ItemClick"
          SelectionMode="None"
          TabIndex="1"
          Padding="0"
          Margin="0"
          BorderThickness="0"
          IsSwipeEnabled="True"
          IsItemClickEnabled="True"
          ScrollViewer.VerticalScrollBarVisibility="Auto" >
    <ListView.HeaderTemplate>
        <DataTemplate>
            <Grid Margin="0,0,0,0" Width="1366" Height="Auto" HorizontalAlignment="Left">
                <Grid.Resources>
                        <Style TargetType="TextBlock" BasedOn="{StaticResource SearchGridResultsHeaderTextBlock}">
                            <Setter Property="HorizontalAlignment" Value="Left"></Setter>
                        </Style>
                    </Grid.Resources>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*"/>
                        <ColumnDefinition Width="2*"/>
                        <ColumnDefinition Width="3*"/>
                        <ColumnDefinition Width="2*"/>
                        <ColumnDefinition Width="6*"/>
                        <ColumnDefinition Width="2*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" Text="Permit #" MaxLines="2" TextWrapping="WrapWholeWords"/>
                    <TextBlock Grid.Column="1" Text="County" …
Run Code Online (Sandbox Code Playgroud)

xaml listview uwp-xaml

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

Xamarin表单 - 如何将背景图像添加到内容页面

我正在尝试将背景图像分配给我设计的内容xaml.我尝试了不同的方法,但它没有向我展示背景图像.这是我写的代码:

内容页:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Demo.Welcome"
             BackgroundImage="bg1.jpg">

  <ContentPage.Content>
    <StackLayout  HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Spacing="25" Padding="0" x:Name="stackLayoutMain">
      <Label FontSize="40" Text="WelCome Page" HorizontalOptions="Start" VerticalOptions="StartAndExpand"></Label>
      <Entry Placeholder="Activation Key" WidthRequest="200" FontSize="15" HorizontalOptions="Center" VerticalOptions="StartAndExpand" TextChanged="entryActivationTextChanged" x:Name="entryActivationKey" Keyboard="Numeric" HorizontalTextAlignment="Center"></Entry>
      <Button
        x:Name="buttonActivate"
        BackgroundColor="#fff"
        Text="Activate"
        WidthRequest="100"
        HeightRequest="50"
        HorizontalOptions="Center"
        VerticalOptions="StartAndExpand"
        TextColor="#377CC1"
        IsVisible="False"
        Clicked="buttonActivateClicked" >
      </Button>
    </StackLayout>
  </ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

bg1.jpg 我的便携式项目中的图像,我想设置为背景,我已设置属性

  • Build Action = "Content"
  • Copy to Output Directory = "Copy Always"

以下是我的项目的目录结构.

目录结构

c# xaml xamarin xamarin.forms

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

将数据传递给片段视图模型mvvmcross

所以我的活动有一个带有2个片段的标签页.

  public class RecipeDetailActivity : BaseFragmentActivity<RecipeDetailViewModel>
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.RecipeDetailView);

            AttachActionBar();
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.Title = "Recipe details";

            var viewPager = FindViewById<ViewPager>(Resource.Id.main_view_pager);

            if (viewPager != null)
            {
                var fragments = new List<MvxViewPagerFragmentInfo>();
                fragments.Add(
                    new MvxViewPagerFragmentInfo("Ingrediente", typeof(RecipeFlavoursFragment), typeof(RecipeFlavoursViewModel)));
                fragments.Add(
                    new MvxViewPagerFragmentInfo("Flavours", typeof(RecipeIngridientsFragment), typeof(RecipeIngridientsViewModel)));

                viewPager.Adapter = new MvxFragmentPagerAdapter(this, SupportFragmentManager, fragments);


                viewPager.Adapter = new MvxFragmentPagerAdapter(this, SupportFragmentManager, fragments);
                var tabLayout = FindViewById<TabLayout>(Resource.Id.main_tablayout);
                tabLayout.SetupWithViewPager(viewPager);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我使用以下代码显示此页面.

   private void SelectRecipe(RecipeModel recipe)
   {
            var recipeJson = JsonConvert.SerializeObject(recipe);

            ShowViewModel<RecipeDetailViewModel>(new { recipe = recipeJson …
Run Code Online (Sandbox Code Playgroud)

c# android-fragments mvvmcross

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

如何在uwp平台中将图像转换为字节数组

我需要将图像转换为字节数组以将其存储在数据库中.而且我还需要将该数组转换回图像.我做了谷歌研究,但我找不到解决方案,因为在UWP平台上有些api不可用.

c# uwp windows-10-universal

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

Windows Phone 8.1摄像头初始化

我知道有更多重复的问题,但请,这对我来说非常重要.我现在很难用Windows Phone 8.1 C#相机初始化.

async private void InitCamera_Click(object sender, RoutedEventArgs e)
    {
        captureManager = new MediaCapture();
        await captureManager.InitializeAsync();

         try 
        {
            captureManager = new Windows.Media.Capture.MediaCapture();
            await captureManager.InitializeAsync();

            if (captureManager.MediaCaptureSettings.VideoDeviceId != "" && captureManager.MediaCaptureSettings.AudioDeviceId != "") 
            {
                System.Diagnostics.Debug.WriteLine("Init successful");


                captureManager.RecordLimitationExceeded += new Windows.Media.Capture.RecordLimitationExceededEventHandler(RecordLimitationExceeded);
                captureManager.Failed += new Windows.Media.Capture.MediaCaptureFailedEventHandler(Failed); 
            } 
            else 
            {
                System.Diagnostics.Debug.WriteLine("No Device");
            } 
        }
         catch (Exception exception)
         {
             System.Diagnostics.Debug.WriteLine("Exception raised!!!!:" + exception);
         } 
    }
Run Code Online (Sandbox Code Playgroud)

这是我初始化相机的代码,但由于某种原因,它在Lumia 920 上的Windows.Media.Capture.MediaCapture()构造函数调用失败,System.UnauthorizedAccessException并且在模拟器上也是访问冲突.我已经用Google搜索了这个问题,但到目前为止还没有答案.有些人告诉我不仅应该启用网络摄像头,还要启用麦克风,但这并没有解决我的问题.一切似乎设置得很好,所有访问权限都在app清单中授予.另外我想问你,如果你有一些很好的工作实例/教程用相机拍照,请提供.

c# camera visual-studio windows-phone-8.1

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

取消Windows 10 BackgroundDownloader

我想为BackgroundDownloader实现一个超时功能.当我达到超时时,我无法取消下载操作.所以我这样使用它:

   public async void downloadFile(string fileUrl, string fileName) {
        var myFolder = await StorageFolder.GetFolderFromPathAsync(Package.Current.InstalledLocation.Path);
        var myFile = await myFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

        var downloader = new BackgroundDownloader();
        var downloadOperation = downloader.CreateDownload(new Uri(fileUrl), myFile);

        var task = Task.Run(async () => await downloadOperation.StartAsync().AsTask());
        if ( task.Wait(TimeSpan.FromMilliseconds(1000)) ) {
            // file is downloaded in time

        } else {
            // timeout is reached - how to cancel downloadOperation ?????

        }
    }
Run Code Online (Sandbox Code Playgroud)

我在努力:

downloadOperation.StartAsync().Cancel();
Run Code Online (Sandbox Code Playgroud)

我明白了

WinRT信息:此操作已经开始.调用AttachAsync以附加到正在运行的下载/上载.

downloadOperation.AttachAsync().Cancel();
Run Code Online (Sandbox Code Playgroud)

我明白了

抛出异常:Project.exe WinRT信息中的"System.Runtime.InteropServices.COMException":此操作未启动.调用StartAsync以启动操作.附加信息:在意外时间调用方法.

任何想法都会被贬低!

c# win-universal-app

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

Windows 8.1商店应用程序MAKEPRI构建错误

在构建任何新创建的项目时,我不断收到以下两个错误,或者在使用Visual Studio 2013的Windows Store项目中出现旧错误

Error   1   Initializing Indexer    c:\Temp\App4\App4\MakePri   App4
Error   2   Schema Validation Failed. The attribute 'targetOsVersion' on the element 'resources' is not defined in the DTD/Schema.  c:\Temp\App4\App4\MakePRI   App4
Run Code Online (Sandbox Code Playgroud)

将MSBuild项目构建输出详细程度转换为Diagnostic我看到以下内容

2>Using "GenerateProjectPriFile" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.Build.AppxPackage.dll".
2>Task "GenerateProjectPriFile" (TaskId:159)
2>  Task Parameter:MakePriExeFullPath=C:\Program Files (x86)\Windows Kits\8.0\bin\x64\MakePri.exe (TaskId:159)
2>  Task Parameter:PriConfigXmlPath=obj\Debug\priconfig.xml (TaskId:159)
2>  Task Parameter:
2>      IndexFilesForQualifiersCollection=
2>          obj\Debug\layout.resfiles
2>          obj\Debug\resources.resfiles (TaskId:159)
2>  Task Parameter:ProjectPriIndexName=b3cbc7ac-25e8-4dda-a091-231a51997222 (TaskId:159)
2>  Task Parameter:InsertReverseMap=False (TaskId:159)
2>  Task Parameter:ProjectDirectory=C:\@Personal\Projects\Squeezy2\Squeezy\Squeezy\ (TaskId:159)
2>  Task Parameter:OutputFileName=C:\@Personal\Projects\Squeezy2\Squeezy\Squeezy\bin\Debug\resources.pri (TaskId:159)
2> …
Run Code Online (Sandbox Code Playgroud)

windows-store-apps visual-studio-2013

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

System.UnauthorizedAccessException'发生在Microsoft.Xna.Framework.ni.dll中引发截屏windows phone 8

我正在尝试捕获屏幕截图并将其保存为jpeg MediaLibrary但已收到

在lib.SavePicture(filePath,ms)中的Microsoft.Xna.Framework.ni.dll中发生System.UnauthorizedAccessException类型的第一次机会异常;

我的代码:

public static void SaveToMediaLibrary(FrameworkElement element, string title)
{
    using (MemoryStream ms = new MemoryStream())
    {
        bmp.SaveJpeg(ms, (int)element.ActualWidth, (int)element.ActualHeight, 0, 100);
        var lib = new MediaLibrary();
        var filePath = string.Format(title + ".jpg");
        ms.Seek(0, SeekOrigin.Begin); 
        lib.SavePicture(filePath, ms);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Windows Phone 8模拟器进行测试.我错过了什么?

c# media screenshot windows-phone-8

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