自動化無しに生活無し

WEB開発関係を中心に備忘録をまとめています

  • composerでLaravel9.xプロジェクトが作れない問題に対処する【php8.1】

    ある日、composerコマンドを実行してLaravelプロジェクトを作ろうにも、エラーが出て作れない。 composer create-project --prefer-dist laravel/laravel testlaraveler1 を実行すると下記が得られる。 Creating a "laravel/laravel" project at "./testlaraveler1" Info from https://repo.packagist.org: #StandWithUkraine Installing laravel/laravel (v9.3.5) - Downloading laravel/laravel (v9.3.5) - Installing laravel/laravel (v9.3.5): Extracting archive Created project in /home/akagi/Documents/programming/php/laravel_test03/testlaraveler1 > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages. Problem 1 - spatie/laravel-ignition[1.0.0, ..., 1.4.0] require ext-curl * -> it is missing from your system. Install or enable PHP's curl extension. - Root composer.json requires spatie/laravel-ignition ^1.0 -> satisfiable by spatie/laravel-ignition[1.0.0, ..., 1.4.0]. To enable extensions, verify that they are enabled in your .ini files: - /etc/php/8.1/cli/php.ini - /etc/php/8.1/cli/conf.d/10-opcache.ini - /etc/php/8.1/cli/conf.d/10-pdo.ini - /etc/php/8.1/cli/conf.d/15-xml.ini - /etc/php/8.1/cli/conf.d/20-calendar.ini - /etc/php/8.1/cli/conf.d/20-ctype.ini - /etc/php/8.1/cli/conf.d/20-dom.ini - /etc/php/8.1/cli/conf.d/20-exif.ini - /etc/php/8.1/cli/conf.d/20-ffi.ini - /etc/php/8.1/cli/conf.d/20-fileinfo.ini - /etc/php/8.1/cli/conf.d/20-ftp.ini - /etc/php/8.1/cli/conf.d/20-gettext.ini - /etc/php/8.1/cli/conf.d/20-iconv.ini - /etc/php/8.1/cli/conf.d/20-phar.ini - ...
  • 【Django】django-admin、python、pip、コマンドが動作しない場合の対処法【環境構築問題】

    いわゆる、PATHが通っていない状態 Pythonのインストーラーでインストールする時、『add Python 3.x to PATH』というチェック項目がある。 そこにチェックを入れることで、pythonコマンドが使えるようになる。 参照元:https://bluebirdofoz.hatenablog.com/entry/2019/01/19/141007 django-adminコマンドが使えない時、 django-admin startproject config . pythonか ...
  • 【Django】FontAwesomeで星のアイコンを使ったレビューの投稿と表示

    最終的にこのようになる。 今回はテンプレートのwithとcenterは不使用とした。 そして、5つ星の内、4つ星でレビューした場合、空の星を1つ描画する仕様に仕立てた。 モデル from django.db import models from django.core.validators import MinValueValidator,MaxValueValidator MAX_STAR = 5 class Review(models.Model): comment = models.CharField(verbose_name="コメント",max_length=500) star = models.IntegerField(verbose_name=&qu ...
  • 【Python】pipで翻訳系ライブラリのgoogletransをインストールする【※バージョン指定しないとエラー】

    グーグル翻訳を手軽に試すことができる、Pythonライブラリのgoogletrans。 だが、インストールするバージョンの指定を間違えると、正常に動作してくれない不具合が報告されている。 下記コマンドを実行してインストールするべし。 pip install googletrans==3.1.0a0 その上で、下記を実行する。 from googletrans import Translator translator = Translator() string_ja = "Pythonの勉強は楽しい" trans_en = translator.translate(string_ja, dest="en") print(trans_en.text) 正常に翻訳されている。 ...
  • 【Django】sorted関数とoperatorでモデルのフィールド、メソッドを指定してソーティング・並び替えをする【ランキングの実装に有効】

    例えば、モデルがこうだったとする。 from django.db import models class Topic(models.Model): comment = models.CharField(verbose_name="コメント",max_length=2000) score = models.IntegerField(verbose_name="スコア") def twice(self): return self.score*2 ビューでこのようにすることで、モデルフィールドもしくはモデルメソッドでソーティングができる。 from django.shortcuts import render,redirect from django.views import View from .models import ...
  • 【JavaScript】.replace()で検索した文字列すべてを置換したい場合は正規表現を使う

    例えば、以下の文字列の,を に書き換えたいとする。 let data = "aaa,bbb,ccc"; 文字列の置換処理は.replace()で実現できるから、こうすれば良いと思いがちだが実は違う。 console.log(data.replace(","," ")); // aaa bbb,ccc デフォルトでは最初にヒットした文字列しか置換してくれない。検索した文字列を全て置換したい場合、このようにする。 console.log(data.replace( /,/g , " ")); // aaa bbb ccc ちなみにPythonでは.replace()を使うと全て置換してくれる。だから、Pythonでreplaceを使 ...
  • Sendgridのアカウントが一時的に凍結された場合の対処法と対策

    • 作成日時:
    • 最終更新日時:
    • Categories: インフラ
    • Tags: sendgrid tips
    某日、Sendgridからメールが届く。内容は下記。 Dear Twilio SendGrid Customer, Your Twilio SendGrid account has been temporarily suspended as we have detected that your account's credentials (password and/or API key) are publicly listed on the code repository GitHub. This is a dangerous practice which may result in your account being used by unauthorized third parties to send malicious content and which may incur damage to your reputation as a quality sender and charges against your account for high usage that you did not perform. Before you ask for your account's reactivation, please ensure that you: 1) Change your account's password: https://sendgrid.com/docs/ui/account-and-settings/resetting-your-username-and-password. If your account was created using Heroku or IBM BlueMix, you must use our password reset form. 2) Delete and update exposed API keys in your account [APIのID] : https://sendgrid.com/docs/ui/account-and-settings/api-keys/#delete-an-api-key 3) Enable two-factor authentication for your account 4) Remove your account credentials and API keys from any public listings on code repositories or associated comments on sites such as GitHub or BitBucket. Please see the following link(s) for locations where your credentials ...
  • 【Django】settings.pyのINSTALLED_APPSにはどのように書くのが適切か【順番とapps】

    公式の書き方 Django公式によると、下記のように書くのが適切。 INSTALLED_APPS = [ "bbs.apps.BbsConfig", 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] 参照元: https://docs.djangoproject.com/ja/4.0/ref/applications/#configuring-applications 一部媒体における書き方 一方で一部の媒体では以下のように書かれてある。 INSTALLED_APPS = [ "bbs", 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] どちらが正しいのか? bbs/apps.pyにて、下記のように仕立てる。 from django.apps import AppConfig class BbsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'bbs' verbose_name = "簡易掲示板" これは管理サイトで操作するモデルの一覧を表記する際、verbose_nameを追加 ...
  • 【Django】ユーザー作成時に何らかの処理を行う方法【saveメソッドオーバーライド】

    カスタムユーザーモデルを使用している時、ユーザーアカウント新規作成時に何らかの処理を行って欲しい場合。 そういう時はSignupFormのsaveメソッドをオーバーライドする。 SignUpFormのコード from django.contrib.auth.forms import UserCreationForm from .models import CustomUser class SignupForm(UserCreationForm): class Meta(UserCreationForm.Meta): model = CustomUser fields = ("username") def save(self, request, commit=True, *args, **kwargs): #ユーザーモデルのオブジェクト作成(ただし、保存をしない) user = super().save(commit=False) #生のパスワードをハッシュ化した上で、モデルオブジェクトの属性にセットする。 user.set_password(self.cleaned_data["password1"]) #保存す ...
  • JavaScript(jQuery)でQRコードを表示させる

    例えば、ユーザーの一部がPCでの操作をやめて、スマホで操作したいと思ったとする。 こういう時QRコードを表示させる、ブラウザのアドオンや機能を使えば良いが、ユーザーにそれを強いるのはやや酷である。 そこで、jQueryを使用して、QRコードを簡単に表示させると良いだろう。 コード <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Hello World test!!</title> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script> <script> window.addEventListener("load" , function (){ let qrtext = location.href; let utf8qrtext = unescape(encodeURIComponent(qrtext)); $("#qrcode").html(""); $("#qrcode").qrcode({width:160,height:160,text:utf8qrtext}); }); </script> </head> <body> <div id="qrcode"></div> </body> </html> 動かすとこうなる。 結論 下記を参照。 https://github.com/jeromeetienne/jquery-qrcode ...