GoogleAppEngineBoilerplateLegacy
==============================
ThisProjectwasSponsoredbyPyCharm
NOTE:ThisProjectisLegacyandusesthefirsttechnologyusedbyGoogleAppEngine,likewebapp2asPythonFrameworkandDataStoreasDataBase.On2016thisprojectwaslegacyanditisrecommedabletousemodermtechnologieslikeFlaskorDjangoasFramework,MySQLasdatabase.Thankseverybodyfortheircontributions,Thecreatorofthisprojectishonoredthatithelpstobringwebtechnologytotheworld.
IntroGoogleAppEngineBoilerplategetsyourprojectoffthegroundquicklyusingtheGoogleAppEngineplatform.CreatepowerfulapplicationsbyusingthelatesttechnologysupportedonGoogleAppEngine.ItwillintroducesnewdeveloperstoAppEngineandadvanceddeveloperstofollowbestpractices.
Tryaonlinedemo
What'saBoilerplate?ABoilerplateisusedtodescribesectionsofcodethatcanbereusedoverandoverinnewcontextsorapplicationswhichprovidesgooddefaultvalues,reducingtheneedtospecifyprogramdetailsineveryproject.(wikipedia)
WhatmakesthisBoilerplateAmazing?Itisfullyfeatured,activelymaintained,andusesthelatestandmostsupportedtechnologiesofGoogleAppEngine.
NewtoGoogleAppEngine?Learnaboutitbywatchingthisvideoof@bslatkinorreadingtheofficialdocumentation.
GetstartedinjustafeweasystepsDownloadthelastversionoftheAppEngineSDKforLinux,MacOSorWindows.DownloadorclonethecodeofthisBoilerplate(here)Runlocally(instructions).Setyour'application'nameinapp.yamlSetcustomconfigparametersinbp_content/themesconfig/localhost.py,config/testing.pyandconfig/production.pylikesecretkey,recaptchacode,saltandother.Boilerplatewillidentifywhichconfigfiletouseinlocal,unittestingandproduction.Togetstarted,lookthedefaultsettingsinbp_includes/config.py.Thosesettingswillbeoverwriteforyourconfigfiles.Mostofthedefaultsettingswillneedtobechangedtoyieldasecureandworkingapplication.SetAuthenticationOptionsdropdowntoFederatedLoginintheGoogleAppEnginecontrolpanel(orifyoudonotwantfederatedlogin,setenable_federated_logintofalseinconfig.py)
Deployitonline(instructions-recommendedsetup:python2.7,highreplicationdatastore)
gcloudconfigsetprojectsandengine;gcloudappdeploy-qapp.yamlcron.yamlPleasenotethatyourcustomapplicationcodeshouldbelocatedinthebp_contentfolderwithinyourowntheme.Theintentionisthatseparatingtheboilerplatecodefromyourapplicationcodewillavoidmergeconflictsasyoukeepupwithfutureboilerplatechanges.
FunctionsandfeaturesAuthentication(SignIn,SignOut,SignUp)FederatedLogin-loginviayourfavoritesocialnetwork(Google,Twitter,etc...)poweredbyOpenIDandOAuthResetPasswordUpdateUserProfileContactFormClientsideandserversideformvalidationAutomaticdetectionofuserlanguageSupportformanyLanguages(English,Spanish,Italian,French,Chinese,Indonesian,German,Russian,etc)VisitorsLogNotificationsandConfirmationforuserswhentheychangetheiremailorpasswordResponsiveDesignforviewingonPCs,tablets,andmobilephones(synchronizedwithTwitter-Bootstrapproject)MobileidentificationUnitTestingErrorhandlingBasicusermanagementfeaturesavailableunder/admin/users/forGoogleApplicationAdministratorsResourcesBoilerplatehasaGooglegroup(gae-boilerplate)fordiscussionsandaTwitteraccount(@gaeboilerplate)forsharingrelatedresources.
OpenSourceIfyouwanttoadd,fixorimprovesomething,createanissueorsendaPullRequest.
Beforecommittingfixeswerecommendrunningtheunitests(intheboilerplatepackage).Thiswillhelpguardagainstchangesthataccidentlybreakothercode.Seethetestingsectionbelowforinstructions.
Feelfreetocommitimprovementsornewfeatures.Feedback,commentsandideasarewelcome.
RunYoucanrunthisprojectdirectlyfromterminalwithFabric.
fabstartAlsoyoucanrunitclearingdatastore.
fabstart:clearUnitTestingRequirements
Installpipwithdistributeinordertoinstallnextpackages.
Beforerunningunittestsitisnecessarytoinstallwebtest,mock,andpyqueryinyourlocalpythoninstallation.
sudopipinstallwebtestsudopipinstallmocksudopipinstallpyqueryThebestwaytorununittestsisthoughFabric.
sudopipinstallFabricRunningUnitTests
TorununittestswithFabricrunfabtestcommandinterminal.AlsoUnittestscanberunviatestrunnerorinEclipsebyrightclickingonthewebfolderandselecting"runas..."->"Pythonunit-test".Youmayneedtoadd/boilerplate/externaltoyourpythonpath.AddingyoursUnitTest
Pleaseaddunittestsforyourapplicationtoyourhandlerfolderinatest.pyfile.Yourownunittestscanbecreatedsimilarlytothoseintheboilerplate.Inheritingfromboilerplate.lib.test_helpers.HandlerHelperswillprovideaccesstoconvenienthandlertestingmethodsusedbytheboilerplate.DeployTodeployyourprojectwithFabric,justrunthiscommandinTerminal.
fabdeployRemembertochangeapplication,version,themeinapp.yamlaccordingtoyourproject.
TechnologiesusedPython2.7.5NDB1.0.10(ThebestdatastoreAPIfortheGoogleAppEnginePythonruntime).Jinja22.6(AfullyfeaturedtemplateengineforPython).WTForms-1.0.2(Formsvalidationframeworkkeepinguserinteractionsecureandflexiblewithorwithoutjavascript).Babel-0.9.6andgaepytz-2011h(Industystandardinternationalizationrendersthesiteinmultiplelanguages).webapp22.5.2(AlightweightPythonwebframework,themostcompatiblewithGoogleAppEngine).webapp2_extras.sessionswebapp2_extras.routeswebapp2_extras.authwebapp2_extras.i18nCodewrittenfollowingtheGooglePythonStyleGuideUnittestingwithunittest,webtest,pyqueryOpenIDlibraryprovidedbyGoogleAppEngineOAuth2forfederatedloginprovidersthatdonotsupportOpenIDFront-endTechnologiesHTML5BoilerplateModernizr2.6.1jQuery1.8.2TwitterBootstrap3.1.1upgradedfrom2.2.1.TemplateforDesktopVersion.HelptotranslatetonewlanguagesorimproveoldtranslationsIneachlocale//LC_MESSAGESdirectorythereisafilemessages.po.Pleasehelpustranslatethetextinthesefiles.msgidisthetextinEnglish.msgstristhetranslationtothelanguageindicatedbythelocalecode.Forexample:
msgid"Changeyourpassword"
msgstr"Cambiartucontraseña"
Requirements
Installbeforepipwithdistribute_setup.py(Readtheenvironmentsetupdocument)
sudopipinstallbabelsudopipinstalljinja2Translating
Toexecutethetranslation,runthesetwocommands.(beforethesecondone,gotolocalefoldertoincludeyourtranslation)
fablangfablang:compileWorkingwithInternationalization(i18n)Thisboilerplatecomesbundledwithbabel,pytz,andautomaticlanguagedetectionwhichtogetherprovidepowerfulinternationalizationcapability.Texttobetranslatedneedstobeindicatedincodeandthentranslatedbyuserslikeyouafterwhichitiscompiledforspeed.
Addingorupdatingtexttobetranslatedoraddingnewlanguagesrequiresmoreworkasindicatedinthestepsbelow:
Texttobetranslatedshouldbeenclosedin_("texttotranslate")in*.pyfiles.
{{..._("texttotranslate")...}}{%..._("texttotranslate")...%}Inhtmltemplatestranslatedtextisindicatedby:
{%trans%}texttotranslate{%endtrans%}NOTE:Translationscanbeaddedtoothertypesoffilestoo.Seebabel.cfgandbabel.cfgdocumentation
Obtainpybabeltoperformthestepsbelow.Youwillneedtoinstallandcompilejinja2andbabel.Notethatyoumayneedtofirstinstallsetuptoolsandeasy_install.pybabel.execanberunfromtheScriptsdirectoryinyourpythoninstallation.
easy_installjinja2babelBabelthenneedstofindalltranslationedtextblocksthroughoutcodeandtemplates.Afterinstallingpybablrunthiscommandtoextractmessages(assuming./isthelocationofthisboilerplate):pybabelextract-F./locale/babel.cfg-o./locale/messages.pot./--sort-output--no-location--omit-header
Updatetranslationsofexistinglanguagesoraddnewlanguages
Updatetranslationsofexistinglanguagesbyrunningthiscommandforeachlocale:pybabelupdate-les_ES-d./locale-i./locale/messages.pot--previous--ignore-obsoleteRunthiscommandforeachlocalebyreplacinges_ESinthecommand.Localenamesarethedirectorynamesin./locale.Addnewlanguages:Runthiscommandforeachnewlanguagetoadd.Youwillneedtoreplacees_ESinthecommandwiththelocalecodetoadd:pybabelinit-les_ES-d./locale-i./locale/messages.potAddthelocaletothelocalesarrayinyourthemes/<your_theme>/config/.Instructionsonhowtopickalocalecodeareprovidedinthecommentsabovethearray.ProvidetranslationsforeachlanguageIneachlocale//LC_MESSAGESdirectorythereisafilemessages.po.Userstranslatethestringsinthesefiles.msgidisthetextinEnglish.msgstristhetranslationtothelanguageindicatedbythelocalecode.Forexample:
msgid"Changeyourpassword"msgstr"Cambiartucontraseña"CompiletranslationsRun:pybabelcompile-f-d./locale
Seewebapp2'stutorialandpybabel'sdocsformoredetails.
Disablingi18n
i18ncanbedisabledandlanguageoptionshidden.Setlocalesinconfig.pytoNoneoremptyarray[]todothis.Thismaybeusefultoprovideaperformanceboostorsimplifysitesthatserveamarketwithonlyonelanguage.Thelocaledirectorycanbesafelyremovedtosavespaceifnotneededbutthebabelandpytzdirectoriescannotberemovedwithoutbreakingcode(importsandtransstatements)atthistime.
SecuritySSL
SSLisenabledsitewidebyaddingsecure:alwaystothesection:-url:/.*inapp.yaml(removethislinetodisable)SSLeitherrequiresafreegoogleappengine*.appspot.comdomainoracustomdomainandcertificateAlternativelySSLcanbeenabledatacontrollerlevelviawebapp2schemes.Usethesecure_schemeprovidedinroutes.pyItisrecommendedtoenablesslsitewidetohelppreventsessionhijackingPasswords
PasswordsarehashedandencryptedwithSHA512andPyCrypto.CSRF
Cross-siterequestforgeryprotectionAcknowledgementsGoogleAppEngineBoilerplateisacollaborativeprojectcreatedbycotowhichisbringingtoyouthankstothehelpoftheseamazingpeople
Top10:Primarycontributors:
TmeryuPeta15Sergue1SabirmostofaPmanacascopycat91Mooosef1shearpresvevaSorced-JimFlaskBoilerplates
gae-initflask-boilerplateHerokuflask-appengine-template
评论