小编Jon*_*ndt的帖子

在laravel中从数据库中检索和显示单个记录

我的控制器中有两种方法.第一个被调用uploads,它显示数据库表中的所有记录,它看起来像这样:

 public function uploads()
    {
        //return Upload::all();
        $uploads = Upload::all();
        return view('uploads')->with('uploads',$uploads);
    }
Run Code Online (Sandbox Code Playgroud)

此功能正常运行,并且在我的视图中成功检索了所有记录.

问题在于第二种方法upload,其目的是在从上载列表中单击其名称时显示单个上载的数据.

目前,我有这个:

 public function upload($id)
{
    return Upload::find($id);
}
Run Code Online (Sandbox Code Playgroud)

而且我不确定如何完成此功能.

我的观点看起来像这样:

 @extends('layouts.app')
@section('content')
    <h1>Uploads</h1>
    @if(count($uploads)>0)
@foreach($uploads as $upload)
    <div class="well">
        <h3><a href="/uploads/{{$upload->id}}">{{$upload->name}}</a> </h3>
        <small>Written on {{$upload->created_at}}</small>
    </div>
        @endforeach
    @else
    <p>No uploads found</p>
    @endif

@endsection
Run Code Online (Sandbox Code Playgroud)

我不太确定要放什么web.php,所以我的路线看起来像这样:

    Route::get('/uploads', function () {
    return view('uploads');
});

Auth::routes();
Route::get('/uploads','UploadController@uploads')->name('uploads');
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我做这项工作吗?我只想在单击上传名称时看到关联数组与数据库中的记录.在路线和视图中我需要添加什么?

php laravel laravel-5

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

当我使用cleaning_data时,为什么我没有得到干净的数据

我正在尝试为我的网站创建一个登录表单,但是当我在views.py中使用cleaning_data时,我得不到正确的数据.这是我的代码:

views.py

def login_page(request):
    form = LoginForm(request.POST or None)
    context = {
        'form': form
    }
    if form.is_valid():
        print(form.cleaned_data)
        username = form.cleaned_form.get("username")
        password = form.cleaned_form.get("password")
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            return redirect("/")
        else:
            print("Error")
    return render(request, "auth/login.html", context)
Run Code Online (Sandbox Code Playgroud)


forms.py

class LoginForm(forms.Form):
    username = forms.CharField(
        widget=forms.TextInput(
            attrs={
                "class": "form-control",
                "placeholder": "Username"
            }
        )
    )
    password = forms.CharField(
        widget=forms.PasswordInput(
            attrs={
                "class": "form-control",
                "placeholder": "Password"
            }
         )
    )
Run Code Online (Sandbox Code Playgroud)


的login.html

<form action="POST">{% csrf_token %}
    {{ form }}
    <button …
Run Code Online (Sandbox Code Playgroud)

python forms authentication django login

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

"Spanner操作失败"创建NULL_FILTERED索引

我无法在Cloud Spanner表上创建索引,收到错误"Spanner operation failed".

即使将簇大小增加到6到16个节点,我也无法在~1200万行表上创建两个索引.

扳手操作失败

我做了什么:

  • objects在3节点集群上的Spanner中创建表
  • 表具有10-12列组成的STRING,INT64以及一个ARRAY<STRING>
  • 主键是两列; 分片值(散列object_id)和object_id
  • 加载~1200万行
  • 加载时表没有索引(主键除外)
  • 加载挂钩3节点; 升级到6个节点

我尝试了什么:

  • 试图建立三个索引(通过控制台中的DDL) - 收到"扳手操作失败"
  • Spanner节点数从6 - >增加到12,
  • 能够构建3个索引中的1个(UNIQUE在单列STRING上)
  • 试图构建其他两个索引(UNIQUE NULL_FILTERED在单列STRING上) - 收到"扳手操作失败"
  • 从12 - > 16(最大帐户)增加Spanner节点
  • 试图构建其他两个索引(UNIQUE NULL_FILTERED在单列STRING上) - 收到"扳手操作失败"

我还尝试了什么(更新):

  • 删除了NULL_FILTERED子句并尝试构建其他两个索引.没有解决,仍然无法建立.

database google-cloud-platform google-cloud-spanner

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

webpack不反映带有react和django的js文件中的更改

我正在尝试使用React Frontend和Django Rest Framework后端构建一个应用程序.我使用webpack_loader并按照在线说明进行设置.我从Amazon CDN提供静态文件,但是当我通过webpack.config.js在本地测试时,我对js文件的本地更改没有反映出来python manage.py run server

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
var BundleTracker = require('webpack-bundle-tracker');

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: {
      index: ["./js/index.js"],
      explore: ["./js/explore.js"],
      post: ["./js/post.js"]
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0'],
          plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
        }
      }
    ]
  },
  output: {
    path: __dirname + …
Run Code Online (Sandbox Code Playgroud)

django reactjs webpack

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

无法将类型&lt;class'werkzeug.datastructures.File.Storage&gt;的对象转换为张量

我正在编写一个使用flask框架的客户端python文件,并在docker机器中运行它。因此,这需要一个输入文件并产生输出。但是它引发了无法转换为张量的错误。

tf.app.flags.DEFINE_string('server', 'localhost:9000', 'PredictionService host:port')
FLAGS = tf.app.flags.FLAGS

app = Flask(__name__)

class mainSessRunning():

    def __init__(self):
        host, port = FLAGS.server.split(':')
        channel = implementations.insecure_channel(host, int(port))
        self.stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

        self.request = predict_pb2.PredictRequest()
        self.request.model_spec.name = 'modelX'
        self.request.model_spec.signature_name = 'prediction'

    def inference(self, val_x):
        data = val_x
        self.request.inputs['input'].CopyFrom(tf.contrib.util.make_tensor_proto(data))
        result = self.stub.Predict(self.request, 5.0)
        return result

run = mainSessRunning()


# Define a route for the default URL, which loads the form
@app.route('/pred', methods=['POST'])
def pred():
    request_data = request.files['file']
    result = run.inference(request_data)
    rs = json_format.MessageToJson(result)
    return jsonify({'result':rs})
Run Code Online (Sandbox Code Playgroud)

错误提示:

TypeError:无法将类型(类“ …

python machine-learning werkzeug tensorflow tensorflow-serving

5
推荐指数
0
解决办法
307
查看次数

无法访问URL:HTTP/1.1 400 Bad URI

我想通过composer创建一个新的laravel项目,我遇到了这个错误

 [Composer\Downloader\TransportException]
  The 'http://packagist.org/p/fideloper/proxy%249271e19129358853986ed3ca9315ced11a42439a57f49537033c3b436a6ff543.json
  ' URL could not be accessed: HTTP/1.1 400 Bad URI
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

php cmd laravel composer-php

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

从HTML,CSS和JavaScript中获取干净的字符串

目前,我正试图在sec.gov上搜索10-K提交文本文件.

这是一个示例文本文件:https:
//www.sec.gov/Archives/edgar/data/320193/000119312515356351/0001193125-15-356351.txt

文本文档包含HTML标记,CSS样式和JavaScript等内容.理想情况下,我想在删除所有标签和样式后仅删除内容.

首先,我尝试了get_text()BeautifulSoup 的明显方法.这没有成功.
然后我尝试使用正则表达式删除<和>之间的所有内容.不幸的是,这也没有完全解决.它保留了一些标签,样式和脚本.

有没有人为我实现目标有一个干净的解决方案?

到目前为止,这是我的代码:

import requests
import re

url = 'https://www.sec.gov/Archives/edgar/data/320193/000119312515356351/0001193125-15-356351.txt'
response = requests.get(url)
text = re.sub('<.*?>', '', response.text)
print(text)
Run Code Online (Sandbox Code Playgroud)

python regex web-scraping python-3.x

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

如何将-sf数据帧列表转换为单个数据帧,R中每行几何?

我正在尝试将以下代码的输出转换为数据帧,其中列表是sfc数据帧,其中列包含简单的要素集合 - 每个观察一个多边形.

以下可重复示例和预期输出的输出:

# Reproducible example:  
library(tidyverse)  
library(sf)  
library(magrittr)   

# define radius for circle  
radius <- 40
r <- units::set_units(radius, units::as_units("nmile"), mode = "standard") 
%>% 
units::set_units(units::as_units("m"), mode = "standard")  

# Sample data: 
df <- data.frame(var = c("abc", "bcd", "cab", "dba"), 
lon = c(45,47,1, -109), 
lat = c(7, 10, 59, 30))

# Creating simple features with sf:
df <- df %>% st_as_sf(coords = c("lon", "lat"), dim = "XY")

# Applying Coordinate reference system WGS84:
df <- df …
Run Code Online (Sandbox Code Playgroud)

r transform r-sf

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

dataSnapshot.getChildren() 获取用户 ID,但不获取值

运行此代码时:

private void getData(DataSnapshot dataSnapshot) {
    for(DataSnapshot ds : dataSnapshot.getChildren()){
        Log.d(TAG, "UserID inside getData: "+userID);
        Log.d(TAG, "User Name inside getData: "+ds.child(userID).child("name").getValue());
        Log.d(TAG, "DS inside getData: "+ds.child(userID));

        hospitalCity = String.valueOf(ds.child(userID).child("city").getValue());
        Log.d(TAG, "User city inside getData: "+ds.child(userID).child("city").getValue());

        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

日志显示了这一点:

getData 内的用户 ID:Lsncj8CIsfTQXc7E425AtLuDI5v2
getData 内的用户名:null getData 内的 DS:DataSnapshot { key = Lsncj8CIsfTQXc7E425AtLuDI5v2,value = null }

D/DonorList:getData 内的用户城市:null

这是数据库:

标题]

正如您所看到的,它获取了键,但是null尽管数据库显示其中包含值,但该值仍然存在。

java android firebase firebase-realtime-database

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

Eclipse IDE 显示 JPA 中复合主键类的错误

我有一个带有复合 PK 的实体类,如下所示:
使用 @Embeddable 和 @EmbeddedId 注释。

/** The primary key class for the uom_conversion database table. */
@Embeddable
public class UomConversionPK implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(name="product_id", insertable=false, updatable=false)
    private int productId;

    @Column(name="base_uom_id", insertable=false, updatable=false)
    private int baseUomId;

    @Column(name="to_unit_id", insertable=false, updatable=false)
    private int toUnitId;
    //getters, setters
}
Run Code Online (Sandbox Code Playgroud)

使用它的实体是:

/** The persistent class for the uom_conversion database table. */
@Entity
@Table(name="uom_conversion")
public class UomConversion implements Serializable {
    private static final long serialVersionUID = 1L; …
Run Code Online (Sandbox Code Playgroud)

java eclipse hibernate jpa composite-primary-key

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