<h1>Web Features<aclass="headerlink"href="#web-features"title="Permalink to this headline">¶</a></h1>
<p>Evennia is its own webserver and hosts a default website and browser webclient.</p>
<divclass="section"id="web-site">
<h2>Web site<aclass="headerlink"href="#web-site"title="Permalink to this headline">¶</a></h2>
<p>The Evennia website is a Django application that ties in with the MUD database. Since the website shares this database you could, for example, tell website visitors how many accounts are logged into the game at the moment, how long the server has been up and any other database information you may want. During development you can access the website by pointing your browser to <codeclass="docutils literal notranslate"><spanclass="pre">http://localhost:4001</span></code>.</p>
<blockquote>
<div><p>You may also want to set <codeclass="docutils literal notranslate"><spanclass="pre">DEBUG</span><spanclass="pre">=</span><spanclass="pre">True</span></code> in your settings file for debugging the website. You will then see proper tracebacks in the browser rather than just error codes. Note however that this will <em>leak memory a lot</em> (it stores everything all the time) and is <em>not to be used in production</em>. It’s recommended to only use <codeclass="docutils literal notranslate"><spanclass="pre">DEBUG</span></code> for active web development and to turn it off otherwise.</p>
</div></blockquote>
<p>A Django (and thus Evennia) website basically consists of three parts, a <aclass="reference external"href="https://docs.djangoproject.com/en/1.9/topics/http/views/">view</a> an associated <aclass="reference external"href="https://docs.djangoproject.com/en/1.9/topics/templates/">template</a> and an <codeclass="docutils literal notranslate"><spanclass="pre">urls.py</span></code> file. Think of the view as the Python back-end and the template as the HTML files you are served, optionally filled with data from the back-end. The urls file is a sort of mapping that tells Django that if a specific URL is given in the browser, a particular view should be triggered. You are wise to review the Django documentation for details on how to use these components.</p>
<p>Evennia’s default website is located in <aclass="reference external"href="https://github.com/evennia/evennia/tree/master/evennia/web/website">evennia/web/website</a>. In this folder you’ll find the simple default view as well as subfolders <codeclass="docutils literal notranslate"><spanclass="pre">templates</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">static</span></code>. Static files are things like images, CSS files and Javascript.</p>
<divclass="section"id="customizing-the-website">
<h3>Customizing the Website<aclass="headerlink"href="#customizing-the-website"title="Permalink to this headline">¶</a></h3>
<p>You customize your website from your game directory. In the folder <codeclass="docutils literal notranslate"><spanclass="pre">web</span></code> you’ll find folders <codeclass="docutils literal notranslate"><spanclass="pre">static</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">templates</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">static_overrides</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">templates_overrides</span></code>. The first two of those are populated automatically by Django and used to serve the website. You should not edit anything in them - the change will be lost. To customize the website you’ll need to copy the file you want to change from the <codeclass="docutils literal notranslate"><spanclass="pre">web/website/template/</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">web/website/static/</span><spanclass="pre">path</span><spanclass="pre">to</span><spanclass="pre">the</span><spanclass="pre">corresponding</span><spanclass="pre">place</span><spanclass="pre">under</span><spanclass="pre">one</span><spanclass="pre">of</span></code>_overrides` directories.</p>
<p>Example: To override or modify <codeclass="docutils literal notranslate"><spanclass="pre">evennia/web/website/template/website/index.html</span></code> you need to add/modify <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/template_overrides/website/index.html</span></code>.</p>
<p>The detailed description on how to customize the website is best described in tutorial form. See the <aclass="reference internal"href="Web-Tutorial.html"><spanclass="doc">Web Tutorial</span></a> for more information.</p>
</div>
<divclass="section"id="overloading-django-views">
<h3>Overloading Django views<aclass="headerlink"href="#overloading-django-views"title="Permalink to this headline">¶</a></h3>
<p>The Python backend for every HTML page is called a <aclass="reference external"href="https://docs.djangoproject.com/en/1.9/topics/http/views/">Django view</a>. A view can do all sorts of functions, but the main one is to update variables data that the page can display, like how your out-of-the-box website will display statistics about number of users and database objects.</p>
<p>To re-point a given page to a <codeclass="docutils literal notranslate"><spanclass="pre">view.py</span></code> of your own, you need to modify <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/urls.py</span></code>. An <aclass="reference external"href="https://docs.djangoproject.com/en/1.9/topics/http/urls/">URL pattern</a> is a <aclass="reference external"href="https://en.wikipedia.org/wiki/Regular_expression">regular expression</a> that you need to enter in the address field of your web browser to get to the page in question. If you put your own URL pattern <em>before</em> the default ones, your own view will be used instead. The file <codeclass="docutils literal notranslate"><spanclass="pre">urls.py</span></code> even marks where you should put your change.</p>
<p>Django will always look for a list named <codeclass="docutils literal notranslate"><spanclass="pre">urlpatterns</span></code> which consists of the results of <codeclass="docutils literal notranslate"><spanclass="pre">url()</span></code> calls. It will use the <em>first</em> match it finds in this list. Above, we add a new URL redirect from the root of the website. It will now our own function <codeclass="docutils literal notranslate"><spanclass="pre">myview</span></code> from a new module <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/myviews.py</span></code>.</p>
<blockquote>
<div><p>If our game is found on <codeclass="docutils literal notranslate"><spanclass="pre">http://mygame.com</span></code>, the regular expression <codeclass="docutils literal notranslate"><spanclass="pre">"^"</span></code> means we just entered <codeclass="docutils literal notranslate"><spanclass="pre">mygame.com</span></code> in the address bar. If we had wanted to add a view for <codeclass="docutils literal notranslate"><spanclass="pre">http://mygame.com/awesome</span></code>, the regular expression would have been <codeclass="docutils literal notranslate"><spanclass="pre">^/awesome</span></code>.</p>
</div></blockquote>
<p>Look at <aclass="reference external"href="https://github.com/evennia/evennia/blob/master/evennia/web/website/views.py#L82">evennia/web/website/views.py</a> to see the inputs and outputs you must have to define a view. Easiest may be to copy the default file to <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web</span></code> to have something to modify and expand on.</p>
<p>Restart the server and reload the page in the browser - the website will now use your custom view. If there are errors, consider turning on <codeclass="docutils literal notranslate"><spanclass="pre">settings.DEBUG</span></code> to see the full tracebacks - in debug mode you will also log all requests in <codeclass="docutils literal notranslate"><spanclass="pre">mygame/server/logs/http_requests.log</span></code>.</p>
</div>
</div>
<divclass="section"id="web-client">
<h2>Web client<aclass="headerlink"href="#web-client"title="Permalink to this headline">¶</a></h2>
<p>Evennia comes with a MUD client accessible from a normal web browser. During
development you can try it at <codeclass="docutils literal notranslate"><spanclass="pre">http://localhost:4001/webclient</span></code>.
<aclass="reference internal"href="Webclient.html"><spanclass="doc">See the Webclient page</span></a> for more details.</p>
</div>
<divclass="section"id="the-django-admin-page">
<h2>The Django ‘Admin’ Page<aclass="headerlink"href="#the-django-admin-page"title="Permalink to this headline">¶</a></h2>
<p>Django comes with a built-in <aclass="reference external"href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/">admin website</a>. This is accessible by clicking the ‘admin’ button from your game website. The admin site allows you to see, edit and create objects in your database from a graphical interface.</p>
<p>The behavior of default Evennia models are controlled by files <codeclass="docutils literal notranslate"><spanclass="pre">admin.py</span></code> in the Evennia package. New database models you choose to add yourself (such as in the Web Character View Tutorial) can/will also have <codeclass="docutils literal notranslate"><spanclass="pre">admin.py</span></code> files. New models are registered to the admin website by a call of <codeclass="docutils literal notranslate"><spanclass="pre">admin.site.register(model</span><spanclass="pre">class,</span><spanclass="pre">admin</span><spanclass="pre">class)</span></code> inside an admin.py file. It is an error to attempt to register a model that has already been registered.</p>
<p>To overload Evennia’s admin files you don’t need to modify Evennia itself. To customize you can call <codeclass="docutils literal notranslate"><spanclass="pre">admin.site.unregister(model</span><spanclass="pre">class)</span></code>, then follow that with <codeclass="docutils literal notranslate"><spanclass="pre">admin.site.register</span></code> in one of your own admin.py files in a new app that you add.</p>
</div>
<divclass="section"id="more-reading">
<h2>More reading<aclass="headerlink"href="#more-reading"title="Permalink to this headline">¶</a></h2>
<p>Evennia relies on Django for its web features. For details on expanding your web experience, the <aclass="reference external"href="https://docs.djangoproject.com/en">Django documentation</a> or the <aclass="reference external"href="http://www.djangobook.com/en/2.0/index.html">Django Book</a> are the main resources to look into. In Django lingo, the Evennia is a django “project” that consists of Django “applications”. For the sake of web implementation, the relevant django “applications” in default Evennia are <codeclass="docutils literal notranslate"><spanclass="pre">web/website</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">web/webclient</span></code>.</p>