<li><aclass="reference internal"href="#activating-your-new-character-generation">Activating your new character generation</a></li>
<li><aclass="reference internal"href="#adding-a-no-capcha-recapcha-on-your-character-generation">Adding a no CAPCHA reCAPCHA on your character generation</a><ul>
<li><aclass="reference internal"href="#step-1-obtain-a-sitekey-and-secret-from-google">Step 1: Obtain a SiteKey and secret from Google</a></li>
<li><aclass="reference internal"href="#step-2-installing-and-configuring-the-dedicated-django-app">Step 2: installing and configuring the dedicated Django app</a></li>
<li><aclass="reference internal"href="#step-3-adding-the-capcha-to-our-form">Step 3: Adding the CAPCHA to our form</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<pclass="topless"><ahref="Web-Add-a-wiki.html"
title="previous chapter">Add a wiki on your website</a></p>
<p>This tutorial will create a simple web-based interface for generating a new in-game Character.
Accounts will need to have first logged into the website (with their <codeclass="docutils literal notranslate"><spanclass="pre">AccountDB</span></code> account). Once
finishing character generation the Character will be created immediately and the Accounts can then
log into the game and play immediately (the Character will not require staff approval or anything
like that). This guide does not go over how to create an AccountDB on the website with the right
permissions to transfer to their web-created characters.</p>
<p>It is probably most useful to set <codeclass="docutils literal notranslate"><spanclass="pre">AUTO_CREATE_CHARACTER_WITH_ACCOUNT</span><spanclass="pre">=</span><spanclass="pre">False</span></code> so that all player
characters can be created through this.</p>
<p>You should have some familiarity with how Django sets up its Model Template View framework. You need
to understand what is happening in the basic <aclass="reference internal"href="Web-Character-View-Tutorial.html"><spanclass="doc std std-doc">Web Character View tutorial</span></a>.
If you don’t understand the listed tutorial or have a grasp of Django basics, please look at the
<aclass="reference external"href="https://docs.djangoproject.com/en/4.1/intro/">Django tutorial</a> to get a taste of what Django does,
before throwing Evennia into the mix (Evennia shares its API and attributes with the website
interface). This guide will outline the format of the models, views, urls, and html templates
<h2>Pictures<aclass="headerlink"href="#pictures"title="Permalink to this headline">¶</a></h2>
<p>Here are some screenshots of the simple app we will be making.</p>
<p>Index page, with no character application yet done:</p>
<hrclass="docutils"/>
<p><imgalt="Index page, with no character application yet done."src="https://lh3.googleusercontent.com/-57KuSWHXQ_M/VWcULN152tI/AAAAAAAAEZg/kINTmVlHf6M/w425-h189-no/webchargen_index2.gif"/></p>
<p><imgalt="Having entered an application."src="https://lh6.googleusercontent.com/-HlxvkvAimj4/VWcUKjFxEiI/AAAAAAAAEZo/gLppebr05JI/w321-h194-no/webchargen_index1.gif"/></p>
<p><imgalt="Detail view of character application."src="https://lh6.googleusercontent.com/-2m1UhSE7s_k/VWcUKfLRfII/AAAAAAAAEZc/UFmBOqVya4k/w267-h175-no/webchargen_detail.gif"/></p>
</section>
<hrclass="docutils"/>
<sectionid="installing-an-app">
<h2>Installing an App<aclass="headerlink"href="#installing-an-app"title="Permalink to this headline">¶</a></h2>
<p>Assuming your game is named “mygame”, navigate to your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/</span></code> directory, and type:</p>
<p>This will initialize a new Django app we choose to call “chargen”. It is directory containing some
basic starting things Django needs. You will need to move this directory: for the time being, it is
in your <codeclass="docutils literal notranslate"><spanclass="pre">mygame</span></code> directory. Better to move it in your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web</span></code> directory, so you have
<codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen</span></code> in the end.</p>
<p>Next, navigate to <codeclass="docutils literal notranslate"><spanclass="pre">mygame/server/conf/settings.py</span></code> and add or edit the following line to make
<h3>Installing - Checkpoint:<aclass="headerlink"href="#installing-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>you should have a folder named <codeclass="docutils literal notranslate"><spanclass="pre">chargen</span></code> or whatever you chose in your mygame/web/ directory</p></li>
<li><p>you should have your application name added to your INSTALLED_APPS in <aclass="reference external"href="http://settings.py">settings.py</a></p></li>
</ul>
</section>
</section>
<sectionid="create-models">
<h2>Create Models<aclass="headerlink"href="#create-models"title="Permalink to this headline">¶</a></h2>
<p>Models are created in <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen/models.py</span></code>.</p>
<p>A <aclass="reference internal"href="../Concepts/Models.html"><spanclass="doc std std-doc">Django database model</span></a> is a Python class that describes the database storage of the
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">app_id</span></code> (AutoField): Primary key for this character application sheet.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">char_name</span></code> (CharField): The new character’s name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">date_applied</span></code> (DateTimeField): Date that this application was received.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">background</span></code> (TextField): Character story background.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">account_id</span></code> (IntegerField): Which account ID does this application belong to? This is an
AccountID from the AccountDB object.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">submitted</span></code> (BooleanField): <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">False</span></code> depending on if the application has been submitted yet.</p></li>
<li><p>you should have filled out <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen/models.py</span></code> with the model class shown above
(eventually adding fields matching what you need for your game).</p></li>
<p><em>Views</em> are server-side constructs that make dynamic data available to a web page. We are going to
add them to <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen.views.py</span></code>. Each view in our example represents the backbone of a
specific web page. We will use three views and three pages here:</p>
<ulclass="simple">
<li><p>The index (managing <codeclass="docutils literal notranslate"><spanclass="pre">index.html</span></code>). This is what you see when you navigate to
<li><p>The detail display sheet (manages <codeclass="docutils literal notranslate"><spanclass="pre">detail.html</span></code>). A page that passively displays the stats of a
<li><p>Character creation sheet (manages <codeclass="docutils literal notranslate"><spanclass="pre">create.html</span></code>). This is the main form with fields to fill in.</p></li>
</ul>
<sectionid="index-view">
<h3><em>Index</em> view<aclass="headerlink"href="#index-view"title="Permalink to this headline">¶</a></h3>
<p>Let’s get started with the index first.</p>
<p>We’ll want characters to be able to see their created characters so let’s</p>
<spanclass="n">current_user</span><spanclass="o">=</span><spanclass="n">request</span><spanclass="o">.</span><spanclass="n">user</span><spanclass="c1"># current user logged in</span>
<spanclass="n">p_id</span><spanclass="o">=</span><spanclass="n">current_user</span><spanclass="o">.</span><spanclass="n">id</span><spanclass="c1"># the account id</span>
<spanclass="c1"># submitted Characters by this account</span>
<spanclass="c1"># add the right locks for the character so the account can</span>
<spanclass="c1"># puppet it</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">locks</span><spanclass="o">.</span><spanclass="n">add</span><spanclass="p">(</span><spanclass="s2">" or "</span><spanclass="o">.</span><spanclass="n">join</span><spanclass="p">([</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">db</span><spanclass="o">.</span><spanclass="n">background</span><spanclass="o">=</span><spanclass="n">background</span><spanclass="c1"># set the character background</span>
<div><p>Note also that we basically create the character using the Evennia API, and we grab the proper
permissions from the <codeclass="docutils literal notranslate"><spanclass="pre">AccountDB</span></code> object and copy them to the character object. We take the user
permissions attribute and turn that list of strings into a string object in order for the
create_object function to properly process the permissions.</p>
<p>Most importantly, the following attributes must be set on the created character object:</p>
<ulclass="simple">
<li><p>Evennia <aclass="reference internal"href="../Components/Permissions.html"><spanclass="doc std std-doc">permissions</span></a> (copied from the <codeclass="docutils literal notranslate"><spanclass="pre">AccountDB</span></code>).</p></li>
<li><p>The right <codeclass="docutils literal notranslate"><spanclass="pre">puppet</span></code><aclass="reference internal"href="../Components/Locks.html"><spanclass="doc std std-doc">locks</span></a> so the Account can actually play as this Character later.</p></li>
<li><p>The relevant Character <aclass="reference internal"href="../Components/Typeclasses.html"><spanclass="doc std std-doc">typeclass</span></a></p></li>
<li><p>Character name (key)</p></li>
<li><p>The Character’s home room location (<codeclass="docutils literal notranslate"><spanclass="pre">#2</span></code> by default)</p></li>
<p>Other attributes are strictly speaking optional, such as the <codeclass="docutils literal notranslate"><spanclass="pre">background</span></code> attribute on our
character. It may be a good idea to decompose this function and create a separate _create_character
function in order to set up your character object the account owns. But with the Evennia API,
setting custom attributes is as easy as doing it in the meat of your Evennia game directory.</p>
<p>After all of this, our <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> file should look like something like this:</p>
<spanclass="n">current_user</span><spanclass="o">=</span><spanclass="n">request</span><spanclass="o">.</span><spanclass="n">user</span><spanclass="c1"># current user logged in</span>
<spanclass="n">p_id</span><spanclass="o">=</span><spanclass="n">current_user</span><spanclass="o">.</span><spanclass="n">id</span><spanclass="c1"># the account id</span>
<spanclass="c1"># submitted apps under this account</span>
<spanclass="c1"># add the right locks for the character so the account can</span>
<spanclass="c1"># puppet it</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">locks</span><spanclass="o">.</span><spanclass="n">add</span><spanclass="p">(</span><spanclass="s2">" or "</span><spanclass="o">.</span><spanclass="n">join</span><spanclass="p">([</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">db</span><spanclass="o">.</span><spanclass="n">background</span><spanclass="o">=</span><spanclass="n">background</span><spanclass="c1"># set the character background</span>
<h3>Create Views - Checkpoint:<aclass="headerlink"href="#create-views-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>you’ve defined a <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> that has an index, detail, and creating functions.</p></li>
<li><p>you’ve defined a <aclass="reference external"href="http://forms.py">forms.py</a> with the <codeclass="docutils literal notranslate"><spanclass="pre">AppForm</span></code> class needed by the <codeclass="docutils literal notranslate"><spanclass="pre">creating</span></code> function of
<li><p>your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen</span></code> directory should now have a <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">forms.py</span></code> file</p></li>
</ul>
</section>
</section>
<sectionid="create-urls">
<h2>Create URLs<aclass="headerlink"href="#create-urls"title="Permalink to this headline">¶</a></h2>
<p>You could change the format as you desire. To make it more secure, you could remove app_id from the
“detail” url, and instead just fetch the account’s applications using a unifying field like
account_id to find all the character application objects to display.</p>
<p>To add this to our website, we must also update the main <codeclass="docutils literal notranslate"><spanclass="pre">mygame/website/urls.py</span></code> file; this
will help tying our new chargen app in with the rest of the website. <codeclass="docutils literal notranslate"><spanclass="pre">urlpatterns</span></code> variable, and
<h3>URLs - Checkpoint:<aclass="headerlink"href="#urls-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>You’ve created a <aclass="reference external"href="http://urls.py">urls.py</a> file in the <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen</span></code> directory</p></li>
<li><p>You have edited the main <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/urls.py</span></code> file to include urls to the <codeclass="docutils literal notranslate"><spanclass="pre">chargen</span></code> directory.</p></li>
</ul>
</section>
</section>
<sectionid="html-templates">
<h2>HTML Templates<aclass="headerlink"href="#html-templates"title="Permalink to this headline">¶</a></h2>
<p>So we have our url patterns, views, and models defined. Now we must define our HTML templates that
the actual user will see and interact with. For this tutorial we us the basic <em>prosimii</em> template
that comes with Evennia.</p>
<p>Take note that we use <codeclass="docutils literal notranslate"><spanclass="pre">user.is_authenticated</span></code> to make sure that the user cannot create a character
<p>These files will all go into the <codeclass="docutils literal notranslate"><spanclass="pre">/mygame/web/chargen/templates/chargen/</span></code> directory.</p>
<sectionid="index-html">
<h3>index.html<aclass="headerlink"href="#index-html"title="Permalink to this headline">¶</a></h3>
<p>Please refer back to <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> to see where we define the variables these templates make use of.</p>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">></span>You haven't submitted any character applications.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">></span>You didn't submit this character.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
<p>Our create HTML template will use the Django form we defined back in <aclass="reference external"href="http://views.py/forms.py">views.py/forms.py</a> to drive the
majority of the application process. There will be a form input for every field we defined in
<aclass="reference external"href="http://forms.py">forms.py</a>, which is handy. We have used POST as our method because we are sending information to the
server that will update the database. As an alternative, GET would be much less secure. You can read
up on documentation elsewhere on the web for GET vs. POST.</p>
<li><p>Create a <codeclass="docutils literal notranslate"><spanclass="pre">index.html</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">detail.html</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">create.html</span></code> template in your
<h2>Activating your new character generation<aclass="headerlink"href="#activating-your-new-character-generation"title="Permalink to this headline">¶</a></h2>
<p>After finishing this tutorial you should have edited or created the following files:</p>
<p>This will create and update the models. If you see any errors at this stage, read the traceback
carefully, it should be relatively easy to figure out where the error is.</p>
<p>Login to the website (you need to have previously registered an Player account with the game to do
this). Next you navigate to <codeclass="docutils literal notranslate"><spanclass="pre">http://yourwebsite.com/chargen</span></code> (if you are running locally this will
be something like <codeclass="docutils literal notranslate"><spanclass="pre">http://localhost:4001/chargen</span></code> and you will see your new app in action.</p>
<p>This should hopefully give you a good starting point in figuring out how you’d like to approach your
own web generation. The main difficulties are in setting the appropriate settings on your newly
created character object. Thankfully, the Evennia API makes this easy.</p>
<h2>Adding a no CAPCHA reCAPCHA on your character generation<aclass="headerlink"href="#adding-a-no-capcha-recapcha-on-your-character-generation"title="Permalink to this headline">¶</a></h2>
<h3>Step 1: Obtain a SiteKey and secret from Google<aclass="headerlink"href="#step-1-obtain-a-sitekey-and-secret-from-google"title="Permalink to this headline">¶</a></h3>
<h3>Step 2: installing and configuring the dedicated Django app<aclass="headerlink"href="#step-2-installing-and-configuring-the-dedicated-django-app"title="Permalink to this headline">¶</a></h3>
<p>And add it to the installed apps in your settings. In your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/server/conf/settings.py</span></code>, you
<p>Finally we have to add the CAPCHA to our form. It will be pretty easy too. First, open your
<codeclass="docutils literal notranslate"><spanclass="pre">web/chargen/forms.py</span></code> file. We’re going to add a new field, but hopefully, all the hard work has
been done for us. Update at your convenience, You might end up with something like this:</p>