Skip to main content

Lando set-up running Drupal and Python

Lando is a development environment tool that makes it easier to set up and manage local development environments for web applications. To use Python within a Lando-based development environment, you can follow these general steps:

 

Create a Lando Configuration File

Make sure you have a Lando configuration file (e.g., .lando.yml) in your project's root directory. If you don't have one, you can create it. Here's a basic example:

Using paragraph.getParentEntity() in Drupal Twig templates

In Drupal Twig templates, you can set a variable like paragraph_parent to the parent entity of a paragraph using the paragraph.getParentEntity() method. This is a common approach when you want to access the parent entity (e.g., a node) that contains the paragraph.  Here's how you can do it:

Website viewport

The viewport meta tag in a website's HTML is used to control how the webpage is displayed on a mobile device or in a web browser.  It defines the viewport's behaviour and dimensions.  The viewport meta tag helps create a responsive and mobile-friendly design by adjusting the layout and scaling to fit various screen sizes and orientations, particularly on mobile devices.

Android icon not changing

If the Android app icon is not changing from the default icon (in my situation this was the Capacitor icon), here are some steps to troubleshoot and resolve the issue:

 

Check the Icon Files

Ensure that you have provided the correct icon files in the appropriate directory. In a Capacitor project, the Android app icon should be placed in the res directory under various density-specific folders (e.g., mipmap-hdpi, mipmap-mdpi, mipmap-xhdpi, etc.).

 

keytool error: java.io.IOException: keystore password was incorrect

The "keystore password was incorrect" error in keytool indicates that the password you provided when trying to access or modify a keystore is incorrect. To resolve this issue, you can follow these steps:

 

Verify the Correct Password

Double-check that you are entering the correct password for the keystore. Passwords are case-sensitive, so make sure that the case of the characters in the password matches the one you used when creating or modifying the keystore.

Warning SameSite cookie attribute

In the Drupal Status report, I'm seeing the following message

Not set
This attribute should be explicitly set to Lax, Strict or None. If set to None then the request must be made via HTTPS. See PHP documentation

 

Python absolute or relative path

The os.makedirs(directory_path) function in Python can be used with both absolute and relative paths. Whether you should use an absolute or relative path depends on your specific use case and the location where you want to create the directory:

 

Absolute Path

Use an absolute path when you want to specify the exact location in the file system, starting from the root directory (e.g., /path/to/new/directory).

Move a file from one directory to another in Python

You can move a file from one directory to another in Python using the shutil module.  The shutil module provides functions to perform various file operations, including moving files.  How you can move a file from one directory to another:

Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry

OpenAI request timeout?

Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised ServiceUnavailableError: The server is overloaded or not ready yet..

Try increasing the timeout parameter.  For example, 

llm = ChatOpenAI(temperature=0, model_name=model)

Change to

Subscribe to