![]() Replace the contents of site.css with the following code and save the file. Your folder structure should appear similar to the following image: The site.css file appears in the project and is opened in the editor. In the dialog that appears, select the Stylesheet template, name the file site.css, and select OK. Right-click the static folder and select Add > New item. In Solution Explorer, right-click the HelloFlask folder in the Visual Studio project, select Add > New folder, and name the folder static. In either case, you can organize files under static however you like. The second section in this step demonstrates that method using a simple static data file. When you need to deliver a static file from code, such as through an API endpoint implementation, Flask provides a convenient method that lets you refer to files using relative paths within a folder named static (in the project root). The first section in this step adds a CSS file to your existing page template. Within HTML files, for example, you can refer to static files using a relative path in the project. Such files are referred to as "static" files, and Flask can deliver them automatically without you needing to write any code. Other files such as CSS and JavaScript, are only used by the browser, so the host server simply delivers them as-is whenever they're requested. In a web app built with Python (using any framework), your Python files always run on the web host's server and are never transmitted to a user's computer. Add the following code to it: flaskapp/initdb.py. This file will open a connection to the flaskdb database, create a table called books, and populate the table using sample data. Step 3-2: Serve static files from your app First with your programming environment activated, open a new file called initdb.py in your flaskapp directory. ![]() This way, Visual Studio can supply a rich set of item templates for many project types without asking you to sort through them every time. Visual Studio uses this type identifier to show only those item templates that are suitable for the project type. pyproj) contains a project type identifier that marks it as a Python project. Question: How does Visual Studio know which item templates to offer?Īnswer: The Visual Studio project file (. Adding an item in this manner automatically adds the file to your Visual Studio project and marks the changes for source control. To use a template, select the desired template, specify a name for the file, and select OK. To see available templates, go to Solution Explorer, right-click the folder in which you want to create the item, select Add > New Item: ![]() For each file type (and other files like web.config that you might need for deployment), Visual Studio provides convenient item templates to get you started. Step 3-1: Become familiar with item templatesĪs you develop a Flask app, you typically add many more Python, HTML, CSS, and JavaScript files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |