<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gustavo Henrique.net &#187; json</title>
	<atom:link href="http://www.gustavohenrique.net/brogui/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gustavohenrique.net/brogui</link>
	<description>Só mais um blog com Wordpress</description>
	<lastBuildDate>Tue, 29 Jun 2010 00:00:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django com MySQL, JQuery, Ajax e JSON &#8211; Parte 1</title>
		<link>http://www.gustavohenrique.net/brogui/2008/11/django-com-mysql-jquery-ajax-e-json-parte-1/</link>
		<comments>http://www.gustavohenrique.net/brogui/2008/11/django-com-mysql-jquery-ajax-e-json-parte-1/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 15:23:28 +0000</pubDate>
		<dc:creator>gustavohenrique</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.gustavohenrique.net/site/?p=3</guid>
		<description><![CDATA[Introdução
Django é um framework MVC para desenvolvimento web escrito em python. Proporciona velocidade no desenvolvimento, código limpo e organizado e uma poderosa ferramenta de administração.
Essa é a primeira parte de uma série de artigos sobre como criar um sistema de gestão de provedor de internet utilizando Django, MySQL, Javascript (JQuery), Ajax com JSON, CSS e [...]]]></description>
			<content:encoded><![CDATA[<h2>Introdução</h2>
<p>Django é um framework MVC para desenvolvimento web escrito em python. Proporciona velocidade no desenvolvimento, código limpo e organizado e uma poderosa ferramenta de administração.<br />
Essa é a primeira parte de uma série de artigos sobre como criar um sistema de gestão de provedor de internet utilizando Django, MySQL, Javascript (JQuery), Ajax com JSON, CSS e Linux.  No momento abordaremos apenas a parte de cadastro de clientes.<br />
Para melhor entendimento, é desejável conhecimento básico em desenvolvimento web, Python e Linux.<br />
Instalação, características, manual e outras informações podem ser encontradas no site Django Brasil.<br />
<span id="more-7"></span></p>
<h2>Sobre o Sistema </h2>
<p>Como forma de estudo, resolvi portar as funcionalidades básicas de um sistema antigo que desenvolvi em PHP para Django. Trata-se de um sistema de gestão de provedor de internet, que possibilita o cadastro de clientes, controle de banda, regras de firewall, fluxo de caixa e relatórios gerenciais, interagindo com ferramentas em ambiente Linux. Chamaremos nosso sistema de Sigep &#8211; Sistema de Gestão de Provedor. Nome nada criativo, eu sei, mas vamos deixar assim mesmo.</p>
<h2>Iniciando </h2>
<p>O sistema completo será desenvolvido em Linux, utilizando softwares específicos para o mesmo. É possível desenvolver em Windows e MacOS X, porém o ambiente de produção necessariamente deve ser Linux. Abaixo a descrição do ambiente de desenvolvimento utilizado:</p>
<p>Sistema Operacional: Ubuntu 8.04<br />
IDE/Editor: Komodo Edit para códigos do Django e Geany 0.13 para HTML e CSS<br />
Banco de Dados: MySQL 5.0<br />
Linguagem: Python: 2.5 e Django 1.0</p>
<h3>Instalação</h3>
<p>Não será abordado o processo de instalação nesse artigo. No site www.djangobrasil.com tem um ótimo tutorial de instalação em Windows e Linux.</p>
<h3>Projeto Vs. Aplicação </h3>
<p>Em Django, projeto é o sistema no todo e aplicação é um módulo desse sistema. No nosso projeto Sigep, teremos várias aplicações (módulos), que são: cliente, rede, relatório, etc. Você pode criar uma única aplicação contendo toda funcionalidade do sistema, porém isso deixaria o código mais extenso e de difícil manutenção.</p>
<h3>Criando o Projeto </h3>
<p>Abra um terminal, entre no diretorio onde deseja trabalhar e crie o projeto com o script django-admin.py.<br />
<code><br />
gu@notebook:~$ mkdir projetos<br />
gu@notebook:~$ cd projetos<br />
gu@notebook:~$ django-admin.py startproject sigep<br />
gu@notebook:~$ cd sigep<br />
gu@notebook:~$ ls sigep<br />
__init__.py  manage.py  settings.py  urls.py<br />
</code></p>
<p>O django-admin.py criou um diretório com o nome do projeto contendo os seguintes arquivos:</p>
<p><code>__init__.py</code>: Arquivo vazio. Serve apenas para identificar que é um pacote python<br />
<code>manage.py</code>: Script para gerenciar o projeto no django<br />
<code>settings.py</code>: Arquivo de configuração do projeto<br />
<code>urls.py</code>: Onde é definido o mapeamento das URLs</p>
<h3>Configurando o Projeto</h3>
<p>Vamos editar o arquivo settings.py e incluir as linhas abaixo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
LOCAL = <span style="color: #ff7700;font-weight:bold;">lambda</span> <span style="color: #66cc66;">*</span>args:<span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">dirname</span><span style="color: black;">&#40;</span>__file__<span style="color: black;">&#41;</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>
As linhas acimas criam uma função para retornar o caminho absoluto do diretório do nosso projeto. Agora vamos alterar as seguintes variáveis:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">DATABASE_ENGINE = <span style="color: #483d8b;">'mysql'</span>
DATABASE_NAME = <span style="color: #483d8b;">'sigepdjango'</span>
DATABASE_USER = <span style="color: #483d8b;">'usuario_do_mysql_aki'</span>
DATABASE_PASSWORD = <span style="color: #483d8b;">'senha_do_usuario_do_mysql_aki'</span>
&nbsp;
TIME_ZONE = <span style="color: #483d8b;">'America/Sao_Paulo'</span>
&nbsp;
LANGUAGE_CODE = <span style="color: #483d8b;">'pt-br'</span>
&nbsp;
MEDIA_ROOT = LOCAL<span style="color: black;">&#40;</span><span style="color: #483d8b;">'files'</span><span style="color: black;">&#41;</span>
&nbsp;
TEMPLATE_DIRS = <span style="color: black;">&#40;</span>
    LOCAL<span style="color: black;">&#40;</span><span style="color: #483d8b;">'templates'</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>
O que fizemos acima foi configurar o projeto para acessar nosso banco de dados no MySQL, ajustar o timezone e idioma de acordo com o Brasil, setar o MEDIA_ROOT, que é o diretório onde nossos arquivos externos serão armazenados e definir o diretório templates onde nossos arquivos HTML ficarão.<br />
Agora vamos criar nossa aplicação.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Compartilhe esse artigo</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;submitHeadline=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1&amp;submitSummary=" rel="nofollow" title="Adicionar ao&nbsp;Buzz"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/buzz.png" title="Adicionar ao&nbsp;Buzz" alt="Adicionar ao&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;title=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Del.icio.us"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/delicious.png" title="Adicionar ao&nbsp;Del.icio.us" alt="Adicionar ao&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;title=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;digg"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/digg.png" title="Adicionar ao&nbsp;digg" alt="Adicionar ao&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Facebook"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/facebook.png" title="Adicionar ao&nbsp;Facebook" alt="Adicionar ao&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;title=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Google Bookmarks"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/google.png" title="Adicionar ao&nbsp;Google Bookmarks" alt="Adicionar ao&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;bm_description=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Mister Wong"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Adicionar ao&nbsp;Mister Wong" alt="Adicionar ao&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;T=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Netscape"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/netscape.png" title="Adicionar ao&nbsp;Netscape" alt="Adicionar ao&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;title=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;reddit"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/reddit.png" title="Adicionar ao&nbsp;reddit" alt="Adicionar ao&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;title=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Stumble Upon"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Adicionar ao&nbsp;Stumble Upon" alt="Adicionar ao&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Technorati"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/technorati.png" title="Adicionar ao&nbsp;Technorati" alt="Adicionar ao&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Tip'd"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/tipd.png" title="Adicionar ao&nbsp;Tip'd" alt="Adicionar ao&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1+@+http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Twitter"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/twitter.png" title="Adicionar ao&nbsp;Twitter" alt="Adicionar ao&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2008%2F11%2Fdjango-com-mysql-jquery-ajax-e-json-parte-1%2F&amp;t=Django+com+MySQL%2C+JQuery%2C+Ajax+e+JSON+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Yahoo My Web"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Adicionar ao&nbsp;Yahoo My Web" alt="Adicionar ao&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.gustavohenrique.net/brogui/2008/11/django-com-mysql-jquery-ajax-e-json-parte-1/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
