{"id":7117,"date":"2019-06-26T03:11:26","date_gmt":"2019-06-26T10:11:26","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=7117"},"modified":"2025-06-13T21:10:53","modified_gmt":"2025-06-14T04:10:53","slug":"diary-web-application","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/diary-web-application\/","title":{"rendered":"Criar um aplicativo Web de di\u00e1rio com o Couchbase como back-end"},"content":{"rendered":"<p><b>Michael Aboagye \u00e9 um engenheiro de seguran\u00e7a\/software de back-end que mora em Gana. <\/b><b>Ele est\u00e1 interessado em criar servi\u00e7os de back-end seguros com Python.<\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3152\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/04\/MIKE-IMAGE.jpg\" alt=\"Michael K. Aboagye\" width=\"199\" height=\"199\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/MIKE-IMAGE.jpg 199w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/MIKE-IMAGE-150x150.jpg 150w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/MIKE-IMAGE-65x65.jpg 65w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/MIKE-IMAGE-50x50.jpg 50w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/MIKE-IMAGE-20x20.jpg 20w\" sizes=\"auto, (max-width: 199px) 100vw, 199px\" \/><\/p>\n<p><span style=\"font-weight: 400\">Neste tutorial, veremos como criar um aplicativo Web de di\u00e1rio com base na estrutura do flask com o Couchbase como servidor de back-end. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Ao final deste tutorial, voc\u00ea ser\u00e1 capaz de criar um aplicativo Web simples com a estrutura do Flask para enviar os detalhes dos usu\u00e1rios a um servidor Couchbase. Al\u00e9m disso, voc\u00ea aprender\u00e1 a instalar e configurar um servidor Couchbase.<\/span><\/p>\n<p><b>Pr\u00e9-requisitos<\/b><\/p>\n<p><span style=\"font-weight: 400\">Voc\u00ea precisa dos seguintes pacotes para executar ou clonar o projeto do GitHub.<\/span><\/p>\n<ul>\n<li><b><a href=\"https:\/\/github.com\/pallets\/flask\">Estrutura do Flask<\/a> (vers\u00e3o mais recente)<\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">A estrutura Flask \u00e9 uma microestrutura escrita em Python. \u00c9 uma microestrutura porque n\u00e3o vem com um formul\u00e1rio de valida\u00e7\u00e3o, mecanismo de autentica\u00e7\u00e3o e assim por diante. Ela permite que voc\u00ea personalize os aplicativos \u00e0 sua maneira.<\/span><\/p>\n<ul>\n<li><b><a href=\"https:\/\/jinja.pocoo.org\/\">Modelo Jinja<\/a> (vers\u00e3o mais recente)<\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">O modelo Jinja \u00e9 simplesmente um arquivo de texto que cont\u00e9m vari\u00e1veis e express\u00f5es, que s\u00e3o substitu\u00eddas quando um modelo \u00e9 renderizado ou exibido.<\/span><\/p>\n<ul>\n<li><b><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/downloads\/\">Servidor Couchbase<\/a> (edi\u00e7\u00e3o comunit\u00e1ria) <\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">O Couchbase Server \u00e9 um banco de dados de documentos NoSQL dimension\u00e1vel. Usaremos o servidor Couchbase para armazenar os dados dos usu\u00e1rios. <\/span><\/p>\n<h2><b>Criar um ambiente virtual<\/b><\/h2>\n<p><span style=\"font-weight: 400\">Primeiro, crie um diret\u00f3rio para manter o ambiente virtual usando <\/span><span style=\"font-weight: 400\">mkdir<\/span><span style=\"font-weight: 400\"> comando.<\/span><\/p>\n<p><span style=\"font-weight: 400\">O comando abaixo cria um diret\u00f3rio como<\/span> <span style=\"font-weight: 400\">projeto web<\/span> <span style=\"font-weight: 400\">e o transforma em <\/span><span style=\"font-weight: 400\">projeto web<\/span> <span style=\"font-weight: 400\">diret\u00f3rio<\/span><span style=\"font-weight: 400\">.<\/span><\/p>\n<pre class=\"lang:default decode:true\">mkdir webproject &amp;&amp; cd webproject\r\nVirtualenv diary<\/pre>\n<p><span style=\"font-weight: 400\">Depois disso, mude para o diret\u00f3rio do di\u00e1rio para ativar o ambiente virtual usando os seguintes comandos:<\/span><\/p>\n<pre class=\"lang:default decode:true\">mkdir webproject &amp;&amp; cd webproject\r\n\r\nVirtualenv diary\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Quando estivermos dentro do ambiente virtual, poderemos instalar pacotes sem medo de entrar em conflito com os pacotes do sistema.<\/span><\/p>\n<h2><b>Instalar a estrutura do Flask e outros pacotes<\/b><\/h2>\n<p><span style=\"font-weight: 400\">Nesta se\u00e7\u00e3o, instalaremos a estrutura do Flask escrita em Python e outros pacotes necess\u00e1rios para o projeto.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Vamos instalar os pacotes necess\u00e1rios para este projeto usando o pip e o dpkg.<\/span><\/p>\n<pre class=\"lang:default decode:true\">pip install couchbase\r\n\r\npip install jinja \r\n\r\nPip install flask\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Neste tutorial, executaremos o Couchbase Server por meio do Docker. Voc\u00ea precisa ter o Docker em seu host local ou m\u00e1quina de desenvolvimento para poder <\/span><span style=\"font-weight: 400\">extrair ou baixar imagens do Couchbase de <\/span><a href=\"https:\/\/hub.docker.com\/_\/couchbase\"><span style=\"font-weight: 400\">dockerhub<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Navegue at\u00e9 o terminal e digite o seguinte para acessar o reposit\u00f3rio do DockerHub:<\/span><\/p>\n<pre class=\"lang:default decode:true\">docker login\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Em seguida, ser\u00e1 solicitado que voc\u00ea forne\u00e7a suas credenciais antes de poder acessar ou \"extrair\" imagens do DockerHub.<\/span><\/p>\n<pre class=\"lang:default decode:true\">docker pull couchbase\/server\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Voc\u00ea precisa executar os comandos do Docker como usu\u00e1rio root.<\/span><\/p>\n<p><span style=\"font-weight: 400\">No entanto, se voc\u00ea preferir instalar o Couchbase Server manualmente, o Couchbase oferece duas formas de instala\u00e7\u00e3o para distribui\u00e7\u00f5es baseadas no Debian e no Redat. <\/span><span style=\"font-weight: 400\">Voc\u00ea pode dar uma olhada em <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/downloads\/\"><span style=\"font-weight: 400\">Couchbase<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<h2><b>Fa\u00e7a o download do Python SDK 2.5 para o Couchbase Server<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Para acessar o servidor do Couchbase, precisamos fazer download do cliente Couchbase SDK para acessar um cluster do Couchbase. <\/span><span style=\"font-weight: 400\">O Couchbase fornece SDKs para linguagens de programa\u00e7\u00e3o como Python, .NET e Java.\u00a0<\/span><span style=\"font-weight: 400\">Vamos baixar e instalar o Couchbase SDK para Python usando o pip:<\/span><\/p>\n<pre class=\"lang:default decode:true\">pip install couchbase\r\n<\/pre>\n<h2><\/h2>\n<h2><b>Configurar e iniciar o servidor Couchbase<\/b><\/h2>\n<p><span style=\"font-weight: 400\">Depois de extrair as imagens do Couchbase Server do DockerHub, podemos criar e executar um novo cont\u00eainer usando o seguinte comando:<\/span><\/p>\n<pre class=\"lang:default decode:true\">docker run -d --name db -p 8091-8094:8091-8094 -p 11210:11210 couchbase\r\n<\/pre>\n<p><span style=\"font-weight: 400\">execu\u00e7\u00e3o do docker: Esse comando cria uma camada de cont\u00eainer sobre a imagem do Couchbase e a inicia.<\/span><\/p>\n<p><span style=\"font-weight: 400\">-d : O sinalizador -d significa que o cont\u00eainer \u00e9 executado como um daemon<\/span><\/p>\n<p><span style=\"font-weight: 400\">-name : Esse \u00e9 o nome do novo cont\u00eainer<\/span><\/p>\n<p><span style=\"font-weight: 400\">-p :  Esse sinalizador \u00e9 para mapeamento de portas<\/span><\/p>\n<p><span style=\"font-weight: 400\">Agora estamos executando o servidor Couchbase em um cont\u00eainer.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Em seu navegador, acesse https:\/\/localhost:8091 em seu computador para configurar o servidor Couchbase.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7132\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/06\/build1-300x219.png\" alt=\"\" width=\"300\" height=\"219\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build1-300x219.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build1-768x560.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build1-20x15.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build1.png 902w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span style=\"font-weight: 400\">Como voc\u00ea pode ver, temos op\u00e7\u00f5es para criar um novo cluster ou ingressar em um cluster existente. Vamos escolher a op\u00e7\u00e3o para configurar um novo cluster \u00fanico. <\/span><span style=\"font-weight: 400\">Defina um nome de cluster, crie um nome de usu\u00e1rio para <\/span><span style=\"font-weight: 400\">Administrador<\/span><span style=\"font-weight: 400\"> e uma senha de 6 caracteres, conforme mostrado abaixo: <\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7133\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/06\/build2-300x203.png\" alt=\"\" width=\"300\" height=\"203\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build2-300x203.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build2-768x519.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build2-235x160.png 235w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build2-20x14.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build2.png 844w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span style=\"font-weight: 400\">Vamos usar as configura\u00e7\u00f5es padr\u00e3o. Precisamos definir o nome do host ou o endere\u00e7o IP do nosso novo cluster. N\u00e3o alteraremos o disco de dados, o caminho do disco de \u00edndices e o caminho do disco do Analytics para os fins deste projeto.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7135\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/06\/build3-1-270x300.png\" alt=\"\" width=\"270\" height=\"300\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build3-1-270x300.png 270w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build3-1-300x333.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build3-1-18x20.png 18w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build3-1.png 700w\" sizes=\"auto, (max-width: 270px) 100vw, 270px\" \/><\/p>\n<p><span style=\"font-weight: 400\">Al\u00e9m disso, n\u00e3o h\u00e1 necessidade de alterar as cotas de mem\u00f3ria, a menos que voc\u00ea n\u00e3o tenha RAM suficiente.\u00a0<\/span><span style=\"font-weight: 400\">Por fim, s\u00e3o apresentadas duas op\u00e7\u00f5es: iniciar o servidor Couchbase com as configura\u00e7\u00f5es padr\u00e3o ou configurar a mem\u00f3ria e os servi\u00e7os.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Clique no bot\u00e3o que permite que voc\u00ea configure a mem\u00f3ria e os servi\u00e7os do Couchbase Server. <\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">A se\u00e7\u00e3o Host Name ou IP Address permite definir um nome de host, como <\/span><span style=\"font-weight: 400\">localhost<\/span><span style=\"font-weight: 400\"> ou <\/span><span style=\"font-weight: 400\">192.168.15.12<\/span><span style=\"font-weight: 400\">. O caminho do disco de dados permite que voc\u00ea defina o caminho.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ent\u00e3o <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/5.5\/clustersetup\/create-bucket.html\"><span style=\"font-weight: 400\">criar um balde<\/span><\/a><span style=\"font-weight: 400\"> chamado \"users-data\" por meio do console da Web do Couchbase. <\/span><\/p>\n<h2><b>Escrever c\u00f3digo no lado do servidor para o aplicativo Di\u00e1rio<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">S<\/span><span style=\"font-weight: 400\">At\u00e9 dentro de seu ambiente virtual, crie um arquivo<\/span> <span style=\"font-weight: 400\">nomeado<\/span><b> app.py<\/b><span style=\"font-weight: 400\">. <\/span><span style=\"font-weight: 400\">Dentro do arquivo app.py, copie e cole o seguinte c\u00f3digo:<\/span><\/p>\n<pre class=\"lang:default decode:true\">from flask import Flask \r\nfrom couchbase import Couchbase \r\nclient  = Couchbase.connect(host = \"localhost\", Password = \u201cPassword_here\u201d, bucket = \"Users-data\")\r\n\r\n@app.route('\/home', method=['GET'])\r\ndef home_page():\r\n  return render_template('home.html')\r\n\r\n@app.route('\/home\/create-memo'), method=['POST'])\r\ndef create_memo():\r\n  if method == \u201cPOST\u201d:\r\n     diary = {  \r\n       \"memo\" : request.form[\"memo\"],\r\n       \"year\" : request.form[\"year\"],\r\n      \"month\" : request.form[\"month\"],\r\n      \"day\" :  request.form[\"day\"]\r\n   }\r\n  Key=uuid.uuid1.hex()\r\n  user_doc=json.dumps(diary)\r\n  client.set(key, user_doc)\r\n  return redirect(url_for(\"index\"))\r\nreturn render_view(\"create.html\")\r\n<\/pre>\n<p><span style=\"font-weight: 400\">No c\u00f3digo acima, importamos a estrutura Flask e o cliente Couchbase para Python.\u00a0<\/span><span style=\"font-weight: 400\">Em seguida, nos conectamos ao bucket Users-data por meio do m\u00e9todo de conex\u00e3o do cliente Couchbase. Em seguida, criamos uma rota para a p\u00e1gina inicial e a p\u00e1gina create-memo para os usu\u00e1rios. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Tamb\u00e9m podemos criar uma rota para a p\u00e1gina de mensagens. Essa p\u00e1gina exibir\u00e1 a mensagem enviada por um usu\u00e1rio. <\/span><span style=\"font-weight: 400\">Dentro do arquivo \"app.py\", escreva o seguinte c\u00f3digo para recuperar uma mensagem de usu\u00e1rio espec\u00edfica do servidor Couchbase:<\/span><\/p>\n<pre class=\"lang:default decode:true\">@app.route(\u2018home\/saved-messages\u2018, method=[\u2018GET\u2019,\u2018POST\u2019])\r\ndef get saved_messages():\r\n\r\n    Saved_messages = client.get(key)\r\n    Saved_event = json.loads(saved_messages)\r\n\r\n \r\n    if request.method == \u201cPOST\u201d:    \r\n\r\n       Saved_event.memo = request.form[\u201cmemo\u201d]  \r\n       Saved_event.year = request.form[\u201cyear\u201d] \r\n       Saved_event.month = request.form[\u201cmonth\u201d]\r\n       Saved_event.day = request.form[\u201cday\u201d]     \r\n\r\n       user_doc = json.dumps(diary)   \r\n       client.set(key, user_doc)   \r\n       return redirect(url_for(home_page))\r\n    \r\n    return render_template(\u201csaved.html\u201d, model=Saved_event)  \r\n<\/pre>\n<p><span style=\"font-weight: 400\">Ainda dentro do diret\u00f3rio do projeto, crie um subdiret\u00f3rio usando o comando mkdir, conforme mostrado abaixo:<\/span><\/p>\n<pre class=\"lang:default decode:true\">mkdir templates\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Dentro do diret\u00f3rio de modelos, crie os arquivos home.html, savedmemo.html e postmemo.html com o comando touch:<\/span><\/p>\n<pre class=\"lang:default decode:true\">touch home.html create.html saved.html\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Cole o c\u00f3digo a seguir no arquivo home.html:<\/span><\/p>\n<pre class=\"lang:default decode:true\">&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Welcome to Daily Memo Book&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h1&gt; Remember Your Memorable Events&lt;\/h1&gt;\r\n&lt;p&gt;Welcome to the world of Flask!&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Cole o c\u00f3digo a seguir no arquivo memo.html:<\/span><\/p>\n<pre class=\"lang:default decode:true\">&lt;form action=&quot;\/blog\/pt\/home\/create-memo\/&quot; method=&quot;post&quot; data-trp-original-action=&quot;\/home\/create-memo&quot;&gt;\r\n  &lt;div&gt;\r\n    &lt;label for=&quot;name&quot;&gt;Nome:&lt;\/label&gt;\r\n    &lt;input type=&quot;text&quot; id=&quot;name&quot; name=&quot;name&quot;\r\n  &lt;\/div&gt;\r\n  &lt;div&gt;\r\n    &lt;label for=&quot;month&quot;&gt;Month:&lt;\/label&gt;\r\n    &lt;input type=&quot;text&quot; id=&quot;month&quot; name=&quot;month&quot;&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div&gt;\r\n    &lt;label for=&quot;year&quot;&gt;Year:&lt;\/label&gt;\r\n    &lt;input type=&quot;text&quot; id=&quot;year&quot; name=&quot;year&quot;&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div&gt;\r\n    &lt;label for=&quot;memo&quot;&gt;Memo:&lt;\/label&gt;\r\n    &lt;textarea id=&quot;memo&quot; name=&quot;memo&quot;&gt;&lt;\/textarea&gt;\r\n  &lt;\/div&gt;\r\n&lt;input type=&quot;hidden&quot; name=&quot;trp-form-language&quot; value=&quot;pt&quot;\/&gt;&lt;\/form&gt;      \r\n&lt;div class=&quot;button&quot;&gt;\r\n  &lt;button type=&quot;submit&quot;&gt;Send your message&lt;\/button&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Dentro do arquivo savedmemo.html, cole o seguinte c\u00f3digo para renderizar um formul\u00e1rio que exibir\u00e1 formul\u00e1rios com mensagens salvas:<\/span><\/p>\n<pre class=\"lang:default decode:true\">&lt;form action=&quot;\/blog\/pt\/&rdquo;\/home\/savedmemo&rdquo;\/&quot; method=&quot;&rdquo;POST&rdquo;&quot; data-trp-original-action=&quot;&rdquo;\/home\/savedmemo&rdquo;&quot;&gt;   \r\n   &lt;div&gt;Nome:  \r\n     &lt;input type=&quot;&rdquo;text&rdquo;&quot; name=&quot;&rdquo;name&rdquo;&quot; values=&quot;&rdquo;{{model.Name}}&rdquo;&quot; \/&gt;   \r\n   &lt;\/div&gt;\r\n  \r\n   &lt;div&gt;Month:   \r\n \r\n     &lt;input type=&quot;&rdquo;text&rdquo;&quot;  name=&quot;&rdquo;month&rdquo;&quot; values=&quot;&rdquo;{{model.Month}}&rdquo;&quot; \/&gt;\r\n   &lt;\/div&gt;   \r\n\r\n   &lt;div&gt;Year:  \r\n\r\n     &lt;input type=&quot;&rdquo;text&rdquo;&quot;  name=&quot;&rdquo;year&rdquo;&quot;  values=&quot;&rdquo;{{model.Year}}&rdquo;&quot;  \/&gt;\r\n\r\n   &lt;\/div&gt;    \r\n\r\n   &lt;div&gt;Memo: \r\n\r\n      &lt;input type=&quot;&rdquo;text&rdquo;&quot;  name=&quot;&rdquo;memo&rdquo;&quot;  values=&quot;&rdquo;{{model.Memo}}&rdquo;&quot;  \/&gt;\r\n\r\n   &lt;\/div&gt; \r\n   &lt;div&gt;  \r\n     &lt;input type=&quot;&rdquo;hidden&rdquo;&quot;  name=&quot;&rdquo;&lt;\/form&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;trp-form-language&quot; value=&quot;pt&quot;\/&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Execute o seguinte comando para iniciar o aplicativo baseado em flask, conforme mostrado abaixo:<\/span><\/p>\n<pre class=\"lang:default decode:true\">python app.py\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Abra seu navegador e navegue at\u00e9 o seguinte URL para exibir a p\u00e1gina em que voc\u00ea pode enviar detalhes para o servidor Couchbase:<\/span><\/p>\n<p><a href=\"https:\/\/localhost.com\/home\/create-memo\"><b>https:\/\/localhost.com\/home\/create-memo<\/b><\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7136\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/06\/build4-300x189.png\" alt=\"\" width=\"300\" height=\"189\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build4-300x189.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build4-20x13.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/build4.png 566w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span style=\"font-weight: 400\">Al\u00e9m disso, se quiser navegar at\u00e9 a p\u00e1gina em que as mensagens dos usu\u00e1rios ser\u00e3o exibidas e poder\u00e3o ser editadas ou modificadas e salvas antes de serem enviadas ao Couchbase Server, use o seguinte:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/127.0.0.1\/home\/saved-messages\/:5000\"><b>https:\/\/localhost.com\/home\/saved-messages\/:5000<\/b><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><b>Conclus\u00e3o<\/b><\/h2>\n<p><span style=\"font-weight: 400\">Neste tutorial, aprendemos a criar um aplicativo de di\u00e1rio simples baseado em Flask com o Couchbase Server como back-end<\/span> <span style=\"font-weight: 400\">em que os usu\u00e1rios podem enviar dados por meio de um formul\u00e1rio para um servidor Couchbase.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Voc\u00ea pode fazer download ou clonar o projeto inteiro em <\/span><a href=\"https:\/\/github.com\/Rev0kz\/flask-couchbase-demo\"><span style=\"font-weight: 400\">GitHub<\/span><\/a><span style=\"font-weight: 400\"> se voc\u00ea quiser experimentar.<\/span><\/p>\n<div class=\"entry-content\">\n<div class=\"entry-content\">\n<p><em>Esta postagem foi trazida a voc\u00ea pelo Couchbase\u00a0<a href=\"https:\/\/www.couchbase.com\/blog\/pt\/community\/community-writers-program\/\">Programa de Reda\u00e7\u00e3o Comunit\u00e1ria<\/a><\/em><\/p>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Michael Aboagye is a backend software\/security engineer based in Ghana. He is interested in building secure backend services with Python. In this tutorial, we will look at how we can build a diary web application based on the flask framework [&hellip;]<\/p>","protected":false},"author":53,"featured_media":7107,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814,1815,9139],"tags":[],"ppma_author":[9026],"class_list":["post-7117","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-best-practices-and-tutorials","category-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Build a Diary Web Application with Couchbase as the Back-end - The Couchbase Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/pt\/diary-web-application\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build a Diary Web Application with Couchbase as the Back-end\" \/>\n<meta property=\"og:description\" content=\"Michael Aboagye is a backend software\/security engineer based in Ghana. He is interested in building secure backend services with Python. In this tutorial, we will look at how we can build a diary web application based on the flask framework [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/diary-web-application\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-06-26T10:11:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:10:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1584\" \/>\n\t<meta property=\"og:image:height\" content=\"396\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Laura Czajkowski, Developer Community Manager, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Laura Czajkowski, Developer Community Manager, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/\"},\"author\":{\"name\":\"Laura Czajkowski, Developer Community Manager, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220\"},\"headline\":\"Build a Diary Web Application with Couchbase as the Back-end\",\"datePublished\":\"2019-06-26T10:11:26+00:00\",\"dateModified\":\"2025-06-14T04:10:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/\"},\"wordCount\":1039,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png\",\"articleSection\":[\"Application Design\",\"Best Practices and Tutorials\",\"Python\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/\",\"name\":\"Build a Diary Web Application with Couchbase as the Back-end - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png\",\"datePublished\":\"2019-06-26T10:11:26+00:00\",\"dateModified\":\"2025-06-14T04:10:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png\",\"width\":1584,\"height\":396},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build a Diary Web Application with Couchbase as the Back-end\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220\",\"name\":\"Laura Czajkowski, Developer Community Manager, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/9deb07d5daaa00220534c31768bc4409\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g\",\"caption\":\"Laura Czajkowski, Developer Community Manager, Couchbase\"},\"description\":\"Laura Czajkowski is the Snr. Developer Community Manager at Couchbase overseeing the community. She\u2019s responsible for our monthly developer newsletter.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/pt\/author\/laura-czajkowski\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Build a Diary Web Application with Couchbase as the Back-end - The Couchbase Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/pt\/diary-web-application\/","og_locale":"pt_BR","og_type":"article","og_title":"Build a Diary Web Application with Couchbase as the Back-end","og_description":"Michael Aboagye is a backend software\/security engineer based in Ghana. He is interested in building secure backend services with Python. In this tutorial, we will look at how we can build a diary web application based on the flask framework [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/diary-web-application\/","og_site_name":"The Couchbase Blog","article_published_time":"2019-06-26T10:11:26+00:00","article_modified_time":"2025-06-14T04:10:53+00:00","og_image":[{"width":1584,"height":396,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png","type":"image\/png"}],"author":"Laura Czajkowski, Developer Community Manager, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Laura Czajkowski, Developer Community Manager, Couchbase","Est. reading time":"7 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/"},"author":{"name":"Laura Czajkowski, Developer Community Manager, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220"},"headline":"Build a Diary Web Application with Couchbase as the Back-end","datePublished":"2019-06-26T10:11:26+00:00","dateModified":"2025-06-14T04:10:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/"},"wordCount":1039,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png","articleSection":["Application Design","Best Practices and Tutorials","Python"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/diary-web-application\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/","url":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/","name":"Build a Diary Web Application with Couchbase as the Back-end - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png","datePublished":"2019-06-26T10:11:26+00:00","dateModified":"2025-06-14T04:10:53+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/diary-web-application\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/06\/PYCBC-no-python.png","width":1584,"height":396},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/diary-web-application\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Build a Diary Web Application with Couchbase as the Back-end"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"Blog do Couchbase","description":"Couchbase, o banco de dados NoSQL","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"Blog do Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220","name":"Laura Czajkowski, gerente da comunidade de desenvolvedores, Couchbase","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/9deb07d5daaa00220534c31768bc4409","url":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","caption":"Laura Czajkowski, Developer Community Manager, Couchbase"},"description":"Laura Czajkowski \u00e9 a Snr. Developer Community Manager da Couchbase, supervisionando a comunidade. Ela \u00e9 respons\u00e1vel pelo nosso boletim informativo mensal para desenvolvedores.","url":"https:\/\/www.couchbase.com\/blog\/pt\/author\/laura-czajkowski\/"}]}},"authors":[{"term_id":9026,"user_id":53,"is_guest":0,"slug":"laura-czajkowski","display_name":"Laura Czajkowski, Developer Community Manager, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","author_category":"","last_name":"Czajkowski","first_name":"Laura","job_title":"","user_url":"","description":"Laura Czajkowski \u00e9 a Snr. Developer Community Manager da Couchbase, supervisionando a comunidade. Ela \u00e9 respons\u00e1vel pelo nosso boletim informativo mensal para desenvolvedores."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/7117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=7117"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/7117\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/7107"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=7117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=7117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=7117"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=7117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}