Categories
Online Marketing

Django Web App Development on the Raspberry Pi

So what is Django well Django is a web development framework that saves you time and makes web development a joy using Django. You can build and maintain high-quality web applications with minimal fuss, and we are all going to do that on the Raspberry Pi.

The Raspberry Pi is a tiny computer with enough power to run a Django development server. So here we’re going to attempt installing and deploying our first Django project on the Raspberry Pi and maybe develop a web application on later articles. You may be asking why don’t we just build a web application from scratch without a framework? Well, there will come a time when your application would be needing to connect to a database, and you would end up duplicating your database connection code to other parts of your application.

The practical way is to refactor it into a reusable function. Another problem you’ll encounter is you have to remember to close your database every time and you will end up with a lot of boilerplate code that is prone to mistakes. Your application may not be reusable in a different environment because of some environments, specific configuration. And lastly, if a web designer, who has no experience in coding, wants to redesign the page, he or she might crash the application, because, ideally the logic of the page or the retrieval of information from the database would be separate from the presentation which is the HTML Display of the page, these problems are precisely what a web framework intends to solve.

I’r sure some of you are already familiar with the MVC design pattern or Model View controller design pattern for beginners MVC, like what I mentioned earlier, is a django architecture that separates the logic, the model and the controller from the presentation. The view in django it’s more like an mtv or model template view design pattern. Don’t worry about that now, we’ll get more into that later.

In the meantime, let’s go ahead and install django on the raspberry pi. Okay, so I have here a freshly installed raspbian, which is the official operating system of the raspberry pi. What we’re going to do here is to open up a terminal and install virtual ends, which stands for a virtual environment. To put it simply, virtual environment is an isolated working copy of Python, which allows you to work on a specific project without worry of affecting other projects.

So let’s go ahead and install virtual end, but before we do that, let’s update our package lists by typing sudo. Apt-Get update and when it’s done updating we can go ahead and type in sudo, apt-get install virtual end hit enter, and in my computer, my or my raspberry pi, it’s already been installed. Now that we have our virtual environment installed. We can now create our virtual environment directory that we are going to use for our project to do that.

We just type virtual end dot. Then P, slash user, slash bin, slash Python 3. What this code does is. It makes a hidden directory called vent because in Linux beginning your directory name with the dot, makes that directory hidden and the dash B is an option. You pass virtual environment on what version of Python you want to use. In this case, we want to use Python 3 inside slash user USR, slash bin now hit enter, and when it’s done, if you type LS la you would see that it created our project directory as expected to use it.

We just type source that Ven slash bin. Slash activate you will see our prompt has changed, indicating that we are now in our isolated Python environment. We just type the activate to go back to our regular, prompt and escape our isolated Python environment. We can now install django. There are other ways to install django, but for simplicity, we’ll use pip to install the latest version of django available from PI P or the Python package index repository to do that.

We just type pip, install django and hit enter to test Jiang, the Django installation. You just start up a Python, interactive interpreter by typing Python, and if the installation was successful, we should be able to import Django and check its version. Okay. Moving on, we can now take our first step into creating our first project. A project is a collection of settings for an instance of Django, including database configuration Django, specific options and application specific settings.

So let’s exit our Python shell and type sy, Django admin, the PI or just Django admin, start project. Then the name of our project, which we’ll just name my site for now then hit enter okay. So it says that my site directory already exists just going to delete, delete it for now and make another one. So I’m just going to repeat the command Django admin that I start project my site and then hit enter.

What the start project command does is it creates a directory containing six files? Okay, there we are my site, which is the outer. My site directory is just a container for our project. It name doesn’t matter to Jango, you can rename it to anything. You like manage that PI py is a command line utility that lets you interact with this Jango project in various ways. Type Python manage that hi-oh. We just have to change into the directory first and type Python manage that py help to get a feel for what it can do.

Okay, so here are your options now you should never have to edit this file. It’s created in this directory purely for convenience. Okay, so let’s go back to files that were created. Oh now, it has added a few more files, but we’ll just go over on the basic files that we are concerned about. The next is the inner my site directory. It is the actual Python package for your project and we have our ini’ that py, it’s an empty file required for python to treat the my site directory as a package example a group of python modules – and we also have our settings that pi, which is the Settings configuration for this Django project take a look at it to get an idea of the types of settings available along with their default values.

Okay, so we’ll just skip that for now and we have our URL stat pot, the URLs that PI for this Django project is the table of contents of your jungle powered site. Next. Is we have our WSGI pi an entry point for WSGI compatible web servers to serve your project? And lastly, we have Ras GI that pipe as well as WSGI Jango also supports deploying on a SGI which is the emerging python standard for a synchronous, web servers and applications.

Now to see our barebone application in action. Let’s run the server by changing into the directory of our project, CD, my site and type the command that slash manage, that pi run server the run server launches the built-in django development server, which is a lightweight web server that we can use while developing our site. We will receive a warning message in red telling us we have unapplied migrations welljust.

We will just ignore that for now. Okay, now, if we open up our browser and go to HTTP colon, slash slash 127.0.0.1 colin 8000, which is the IP address that stands for home on port 8000 and if everything goes well, then we’ll see that it works by default. The run server command starts the development server on port 8000, listening only for local connections. If you want to change the server sport, pass it a command-line argument like so so, let’s just ctrl C and run our command again run server and we want to run it on port 8080.

So that’s how you change the port? Ok! So now we will access it here on port 8080. If you want other computers on your local network to be able to view your Django site by visiting your IP address in their web browsers, then you type manage that slash manage that pie run server. 0.0.0.0. 8000. Well, that’s all we have for now in this tutorial. If you have any questions or comments, please post it in the comment section below down below and I’ll do my best to answer them.

If you enjoy the article, please hit the like button and kindly support my blog by subscribing again. My name is Ryan and you are reading recurse TV see you next time.


 

Categories
Online Marketing

Sign-in form best practice

Type切换为文本或密码 请确保包含一个aria-label 以警告将显示密码, 否则,用户可能无意间泄露了密码 说到可访问性 请使用Aria-Describedby 以解释密码约束 并使用您用来描述密码要求的元素 屏幕阅读器会读取标签文本、 输入类型,还有描述 您也需要实时提交之前对数据输入进行认证 HTML表单元素和属性 具有用于基本验证的内置功能 但是在用户输入数据以及尝试提交表单时 还应该使用Javascript进行更强大的验证 请记住,这样做不代表您不需要 验证和净化后端的数据 该视频附带的登录表单Codelab 使用了广泛支持的 Constraint: Validation, API 使用内置的浏览器UI添加自定义验证, 以设置焦点和显示提示, 一件非常重要的事情是:, “, 您无法衡量的东西,您也将无法改善, ” 对于注册和登录表单尤为如此, 您需要设定目标,衡量成功,改善网站并重复, 可用性和实验室测试对进行更改的尝试非常有用, 但您还需要真实世界的数据,以真正了解, 您的用户如何通过分析和, Real User Measurement或Monitoring 体验您的注册和登录表单 您需要监视页面分析 包括注册和登录页面视图 跳出率和退出 请确保添加诸如目标渠道之类的交互分析 用户在哪里放弃注册或登录流程? 事件,您知道用户在与表单进行交互时 会采取什么操作吗? 最后,进行跟踪网站性能: 使用以用户为中心的字段指标 来了解真实用户的真实体验 您的注册和登录表单加载速度是否缓慢?, 如果是,原因是什么?, 最后,一些可帮助减少登录表单丢弃的通用准则, 第一:不要让用户搜寻登录!, 请使用易于理解的措辞 例如 “ 登录, ” , “ 创建帐户, ” 或 “ 注册, ” 在页面顶部放置指向登录表单的链接 功能要明确, 表单并不是用产品和功能吸引人们的地方, 最大限度地减少复杂性, 仅当用户看到提供例如地址或信用卡等 详细信息数据的明显好处时 才向用户询问该数据 在用户开始使用注册表单之前 明确价值主张是什么? 他们将如何从登录中受益? 为用户提供完成注册的具体激励措施 如果可能的话,允许用户使用手机号码 而不是电子邮件地址来标识自己 因为这就是有些用户希望的方式 他们可能不想使用他们的电子邮件 让用户轻松重置密码 并把, “ 忘记密码?, ” 链接放在明显的地方 请确保链接到您的服务条款和隐私政策文档 从一开始就让用户清楚了解 您如何保护他们的数据 最后 — 在注册和登录页面上 为您的公司或组织建立品牌 确保您的字体、风格和语音语调 与您网站的其余部分相匹配 某些表单感觉上与其他内容不属于同一网站, 特别是如果它们具有明显不同的URL 就是这样 这是登录表单最佳实践的基础 您可以从该视频随附的web.

Dev文章 以及代码实验室找到更多信息 我希望为您提供可加入您下一轮工作的一些要点 以改善您的网络网站的表单 当然,注册和登录 不是唯一涉及表单填充且需要大量改进的地方 敬请关注Eiji 他将在网上讨论一些新的付款方式 谢谢观看!