Python——Web2py开发实战:开发一个自己的网站(新手入门级)

article/2025/10/15 0:02:32

目录

一、web2py

二、使用步骤

1.找到一个可以帮助网站运营的工具——pythonanywhere

1)创建账户;

2)创建网站

3) 网站管理

2.我的开端

1)删除example app

2)创建新的app sophia

3)修改参数

 4)修饰

前言        

已经想学开发网站很久了,奈何只会Python,但不会HTML语言。


一、web2py

        当初学时觉得最容易上手的工具。

二、使用步骤

1.找到一个可以帮助网站运营的工具——pythonanywhere

入口:https://www.pythonanywhere.com/

1)创建账户;

Start running……;

 Create a Beginner account;

 

 注册;

 

 创建成功;

2)创建网站

点击Open Web tab后Add a new web app(我已经有一个创建好的网站被我停用了,这时免费的网站只能创建一个,所以需要删除原来的网站才能创建新的);

 一路next(什么注册选择都自己选);

 using this domain already exists说明网络仓库已经有这个文件夹了,而创建新的网站APP需要空的文件路径,因此直接把上面的Directory路径修改一下就好了,Admin Password是网站管理密码(创建需要等待几分钟);

 成功创建,接下来是网站管理了;

        每当你对网站进行修改后,若是刷新网站后没有更新,则是要点击下面的绿色按钮Reload ……;

        若是你想一直让这个网站运行下去,则是要每隔三个月点击黄色按钮Run……;

3) 网站管理

以我的注册网站为例,进入welcome

这是网站的后台入口界面,点击蓝色按钮admin;

 输入管理密码;

 到达后台;

         

 这些东西到这都可以自己探索了,可以自己随便试试。

2.我的开端

1)删除example app

2)创建新的app sophia

3)修改参数

  对menu.py

主要是看上面的菜单栏有些不爽,将他们都隐去。

记得保存。

# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations# ----------------------------------------------------------------------------------------------------------------------
# this is the main application menu add/remove items as required
# ----------------------------------------------------------------------------------------------------------------------response.menu = [(T('sophia'), False, URL('default', 'index'), [])
]# ----------------------------------------------------------------------------------------------------------------------
# provide shortcuts for development. you can remove everything below in production
# ----------------------------------------------------------------------------------------------------------------------
'''
if not configuration.get('app.production'):_app = request.applicationresponse.menu += [(T('My Sites'), False, URL('admin', 'default', 'site')),(T('This App'), False, '#', [(T('Design'), False, URL('admin', 'default', 'design/%s' % _app)),(T('Controller'), False,URL('admin', 'default', 'edit/%s/controllers/%s.py' % (_app, request.controller))),(T('View'), False,URL('admin', 'default', 'edit/%s/views/%s' % (_app, response.view))),(T('DB Model'), False,URL('admin', 'default', 'edit/%s/models/db.py' % _app)),(T('Menu Model'), False,URL('admin', 'default', 'edit/%s/models/menu.py' % _app)),(T('Config.ini'), False,URL('admin', 'default', 'edit/%s/private/appconfig.ini' % _app)),(T('Layout'), False,URL('admin', 'default', 'edit/%s/views/layout.html' % _app)),(T('Stylesheet'), False,URL('admin', 'default', 'edit/%s/static/css/web2py-bootstrap3.css' % _app)),(T('Database'), False, URL(_app, 'appadmin', 'index')),(T('Errors'), False, URL('admin', 'default', 'errors/' + _app)),(T('About'), False, URL('admin', 'default', 'about/' + _app)),]),('web2py.com', False, '#', [(T('Download'), False,'http://www.web2py.com/examples/default/download'),(T('Support'), False,'http://www.web2py.com/examples/default/support'),(T('Demo'), False, 'http://web2py.com/demo_admin'),(T('Quick Examples'), False,'http://web2py.com/examples/default/examples'),(T('FAQ'), False, 'http://web2py.com/AlterEgo'),(T('Videos'), False,'http://www.web2py.com/examples/default/videos/'),(T('Free Applications'),False, 'http://web2py.com/appliances'),(T('Plugins'), False, 'http://web2py.com/plugins'),(T('Recipes'), False, 'http://web2pyslices.com/'),]),(T('Documentation'), False, '#', [(T('Online book'), False, 'http://www.web2py.com/book'),(T('Preface'), False,'http://www.web2py.com/book/default/chapter/00'),(T('Introduction'), False,'http://www.web2py.com/book/default/chapter/01'),(T('Python'), False,'http://www.web2py.com/book/default/chapter/02'),(T('Overview'), False,'http://www.web2py.com/book/default/chapter/03'),(T('The Core'), False,'http://www.web2py.com/book/default/chapter/04'),(T('The Views'), False,'http://www.web2py.com/book/default/chapter/05'),(T('Database'), False,'http://www.web2py.com/book/default/chapter/06'),(T('Forms and Validators'), False,'http://www.web2py.com/book/default/chapter/07'),(T('Email and SMS'), False,'http://www.web2py.com/book/default/chapter/08'),(T('Access Control'), False,'http://www.web2py.com/book/default/chapter/09'),(T('Services'), False,'http://www.web2py.com/book/default/chapter/10'),(T('Ajax Recipes'), False,'http://www.web2py.com/book/default/chapter/11'),(T('Components and Plugins'), False,'http://www.web2py.com/book/default/chapter/12'),(T('Deployment Recipes'), False,'http://www.web2py.com/book/default/chapter/13'),(T('Other Recipes'), False,'http://www.web2py.com/book/default/chapter/14'),(T('Helping web2py'), False,'http://www.web2py.com/book/default/chapter/15'),(T("Buy web2py's book"), False,'http://stores.lulu.com/web2py'),]),(T('Community'), False, None, [(T('Groups'), False,'http://www.web2py.com/examples/default/usergroups'),(T('Twitter'), False, 'http://twitter.com/web2py'),(T('Live Chat'), False,'http://webchat.freenode.net/?channels=web2py'),]),]
'''

 修改default.py

        由于需要自定义网站,所以需要将默认网站接口进行修改。将代码修改以下:

# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------
# This is a sample controller
# this file is released under public domain and you can use without limitations
# -------------------------------------------------------------------------# ---- example index page ----
def index():return auth.wiki() # ---- API (example) -----
@auth.requires_login()
def api_get_user_email():if not request.env.request_method == 'GET': raise HTTP(403)return response.json({'status':'success', 'email':auth.user.email})# ---- Smart Grid (example) -----
@auth.requires_membership('admin') # can only be accessed by members of admin groupd
def grid():response.view = 'generic.html' # use a generic viewtablename = request.args(0)if not tablename in db.tables: raise HTTP(403)grid = SQLFORM.smartgrid(db[tablename], args=[tablename], deletable=False, editable=False)return dict(grid=grid)# ---- Embedded wiki (example) ----
def wiki():auth.wikimenu() # add the wiki to the menureturn auth.wiki() # ---- Action for login/register/etc (required for auth) -----
def user():"""exposes:http://..../[app]/default/user/loginhttp://..../[app]/default/user/logouthttp://..../[app]/default/user/registerhttp://..../[app]/default/user/profilehttp://..../[app]/default/user/retrieve_passwordhttp://..../[app]/default/user/change_passwordhttp://..../[app]/default/user/bulk_registeruse @auth.requires_login()@auth.requires_membership('group name')@auth.requires_permission('read','table name',record_id)to decorate functions that need access controlalso notice there is http://..../[app]/appadmin/manage/auth to allow administrator to manage users"""return dict(form=auth())# ---- action to server uploaded static content (required) ---
@cache.action()
def download():"""allows downloading of uploaded fileshttp://..../[app]/default/download/[filename]"""return response.download(request, db)

 视图修改layout.html

修改掉web2py这个logo;

        找到这一行:

        改成:

 修改index.py;

         将这些代码全换成我下面的这个:

{{extend 'layout.html'}}{{=content}}

到这基本参数修改完毕。来看看最终呈现的网站是什么样子的。

         嗯,网站干净整洁,达到预期。

 4)修饰

注册;

在这个网站进行二次注册,注意密码不能太短也不能太长,要不然注册不了。(名字啊,随便取)

多一个 Edit Page等菜单栏,这下可以对这个网站肆意妄为了。

 

 Edit Page页(可以看看我的编辑)

Edit Page Media

提交 

 最终结果呈现


总结

        没什么好总结的,一开始弄这个也是为了一有点喜欢的人,单箭头的喜欢,嗯,先优秀自己。


http://chatgpt.dhexx.cn/article/y4b8L6Ws.shtml

相关文章

web2py框架

介绍: web2py是一种免费的、开源的web开发框架,采用python语言编写,并且可以使用python编程。 MVC模式:模型Model、视图View、控制器Controller 一、安装 pip install web2py 二、创建项目(Pycharm) 1.选择File->New Project-&…

web2py入门教程(1)

IDE:PyCharm 1、创建web2py项目 在下图左侧选中Web2Py,在右侧填写项目路径和应用名称,我这里是第一次创建,所以直接点击"Create"创建项目,此时会自动下载Web2Py项目框架(如果不是第一次创建&am…

Gitlab 隐藏注册功能

1.用管理员账号登录 2.Admin Area 3.Settings 4.把Sign-up enabled的勾去掉 5.退出重新登录就可以看见只有登录没有注册选项了

GitLab屏蔽用户注册方法:

以管理员身份登录进GitLab平台 点击【Admin Area】 点击【Settings】 页面控制【Sign-up Restrictions】 默认的GitLab登录界面是有注册功能的 将【Sign-up enabled】的勾选框去掉,即取消掉注册功能 滚动到页面最底端,点击【Save】保存按钮&#xff0c…

gitlab安装注册记录——gitlab(一)

一、下载安装(widows版本) git下载地址:https://git-scm.com/download/win 官网下载速度慢的话可以到管家中下载,速度快 安装好右键就可看到 二、注册gitlab账户 官方网址:https://about.gitlab.com/ 如果注册过gi…

配置gitLab的邮件服务,并开启邮箱的验证通知功能

上一篇,讲了 在linux上搭建部署gitlab服务器 这篇讲一下 配置gitLab的邮件服务 为什么需要开启gitLab的邮件服务呢?我觉得至少有以下两个原因 1、搭建好gitLab服务器后,当有新的开发人员需要加入开发时,就可以注册账号了 但是…

GitLab之不允许用户注册-yellowcong

Gitlab默认是运行用户注册的,但是我们现在不想别人注册gitlab,解决的方案,就是在管理员里面配置允许注册。 注册界面 默认情况下,gitlab是允许用户注册的,但是现在我们需要关闭这个注册。 登录到管理 设置Settings,设置登录信…

2020-08-31 ubuntu18.04下安装gitlab,以及使用邮箱注册

最近在ubuntu18.04系统下安装gitlab,把安装之路记录下来 1、安装并配置必要的依赖关系 sudo apt-get update sudo apt-get install -y curl openssh-server ca-certificates 2、接下来,安装Postfix发送通知邮件,因为会用到服务器的外部DNS…

创建gitlab账号并加入群组

先说背景:我想创建个gitlab账号,并且申请加入一个已经存在的项目组,之前只使用过github,没有gitlab账号,所有我找到如下图片的网站,反复注册之后还是失败,用github账号登录,但项目组…

篇二:部署GitLab-创建令牌与GitLab凭证

篇二:部署GitLab ​ 在Kubernetes集群中完成GitLab服务的部署,完成后创建一个公开项目,这里起个名叫springcloud,以NodePort的方式映射了80端口到宿主机的30888,并在gtilab中上传项目。 3.1部署GitLab 下载并解压Je…

gitlab 屏蔽注册功能

以管理员身份登录进GitLab平台点击【Admin Area】 在sign-up Restrictions 取消sign-up enabled保存退出即可 默认的GitLab登录界面是有注册功能的 将【Sign-up enabled】的勾选框去掉,即取消掉注册功能

GitLab CI/CD 基础入门 Runner注册配置使用

特点 开源: CI/CD是开源GitLab社区版和专有GitLab企业版的一部分。(极狐)易于学习: 官方具有详细的学习操作文档。无缝集成: CI/CD是GitLab的一部分,支持从计划到部署,具有出色的用户体验。可扩展: 可以根据需要添加任…

记部署gitlab出现的问题

一、创建gitlab用户时,用户没收到邮件 排除步骤: 使用 gitlab.rb 里面配置的邮件地址向创建 gitlab 用户时配置的邮件地址发送邮件 收件方能正常收到邮件,排除收件方配置了拒收邮件的可能性。使用 gitlab-rails 命令进行测试 gitlab-rails …

Gitlab和gitlab-runner安装和注册

目录 Git和SVN的区别 Gitlab CI/CD工作原理及使用步骤 Gitlab安装 gitlab-runner安装和注册 GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。 公司内部一般会在自己的内网进行搭建Gitlab服务管理…

gitlab如何创建用户并登录

为了大家后期能方便创建用户和使用gitlab,先给大家设置为中文 设置为中文后保存然后刷新页面即可设置为中文 接下来教大家怎么创建git用户并进行登录 创建完用户后需要配置一次密码 配置完密码后退出用户测试进行新用户登录 这里用刚创建的新用户来登录 第一次登…

Gitlab-Runner安装并注册

本文介绍Gitlab-Runner的安装运行(包括docker方式安装运行及二进制直接运行),并介绍如何将Gitlab注册到Gitlab。同时还介绍了gitlab-runner的一些常用操作命令。 安装Gitlab-Runner gitlab-runner可以使用docker方式运行,也可以在…

通过docker搭建gitlab

通过docker搭建gitlab 一、安装 拉取docker镜像 docker pull gitlab/gitlab-ce启动容器 docker run -d -p 4443:443 -p 8080:80 -p 222:22 --name gitlab --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/dat…

gitlab-runner 注册失败

问题: 用docker启动gitlab-runner,注册runner 时报错:PANIC: Failed to register the runner. You may be having network problems。 不仅如此,我用gitlab-runner verify命令,也是报错:ERROR: Verifying r…

gitlab:(二)gitlab注册用户和邀请进入项目的问题

.新注册用户无法在管理员界面激活 在管理员界面无法进行管理,找不到相关的操作界面 当前gitlab版本 尝试降低gitlab版本 卸载之后删除残留文件 安装指定的低版本:gitlab-ce-12.7.5-ce.0.el7.x86_64.rpm yum install policycoreutils openssh-server op…