I want to benchmark the performance of a template website on a modified kernel. I want to use a website template that has 2-3 tiers (frontend, database etc), logic to create users and some logic to store/modify data for each user.
A quick search did not reveal any useful results as of yet.
I've little experience in web development and was hoping that stackoverflow can point me to something useful.
I would suggest taking a look at the Django framework:
http://docs.djangoproject.com/en/1.3/intro/
http://www.djangobook.com/en/2.0/
Django operates using a three tiered (Model, Template, View) design. The Model is the database access layer and will enable you to validate and store information about your users. The Template is the 'presentation layer' that will both determine the layout of your page through html, but has access to your view and its variables. The View is the portion that will contain all of the logic for the page - in a way it works as a median between your model and your template. The url your user visits will determine which view function you load.
If you are interested in the admin capabilities of the framework, take a look at:
http://www.djangobook.com/en/2.0/chapter06/
You could simply download and run one of the sample django applications like:
http://code.google.com/p/django-voting/
or
https://github.com/scrum8/django-job-board/
Or you could just create a clean django project and turn on the admin console.
Related
My company is evaluating Wagtail as a CMS for parts of our website. Currently we're running Python 2.7 and Django 1.5 (don't ask...). We have the ability to run Wagtail on a separate instance which can include the most current versions of Python/Django but we will not be able to run Wagtail out of the box within our main application.
We're looking at using Wagtail strictly as a CMS, then proxying requests from our main website to the Wagtail instance and returning just the generated markup.
Is there anyone who has done something like this, of could offer insight into the process we might take? Does Wagtail offer functionality like this out of the box? What potential pitfalls might we encounter, or things we should watch out for?
This could mean that instead of "entire pages" stored in Wagtail, we treat it as a way to store distinct content fragments: A paragraph of text which would be loaded into our homepage, or the outer wrapper of a dynamic search results page.
Yes, Wagtail does offer functionality like this, via its API:
http://docs.wagtail.io/en/v2.1/advanced_topics/api/
You could consume the API from the front-end of your main website, using JavaScript (React and Vue are popular options for this approach, but they aren't necessary if you don't need a complex Single Page Application with routing etc), or from the back-end, making HTTP requests from the views of your Django 1.5 app.
As for potential pitfalls, the main issue is that Wagtail previews won't work out of the box, since Wagtail doesn't know about how the content will be rendered. If you have a predictable URL structure on the site that's rendering Wagtail API content, the preview mechanism can be configured to handle this.
If the API approach isn't what you have in mind, you could also consider ways of embedding rendered fragments in the main site. For example, if you use Varnish in front of the main site, you could take advantage of Edge Side Includes:
https://varnish-cache.org/docs/3.0/tutorial/esi.html
Finally, you may find this recent talk on Wagtail as a 'headless' CMS useful:
https://www.youtube.com/watch?v=HZT14u6WwdY (video)
https://docs.google.com/presentation/d/1ZYMogOeXKCCmr7hDZnzx0euw2pD5VCwtv3a7zHB4FW0/ (slides)
https://github.com/openstax/openstax-cms (code)
So in the Django tutorials we make a sparse polls application that shows off some of what Django can do, but leaves a lot to be desired when it comes to learning Django (e.g. using their UserCreationForm to make a user portal).
In part of the tutorial they talk about how the admin should be publishing content (e.g. if it were a blog or newspaper) and we set up the admin site where one can make new questions for the polls.
In regard to the blog idea - since an article would be lengthy most likely - I think the correct model would include models.TextField. However, looking at Django's naturally generated admin site for adding / modifying new models with a TextField leaves a lot to be desired.
What if there should be images embedded among the text? or what if there should be formatted text? The admin site does not support a user friendly way to do this.
My question is how to produce a user friendly way for making mixed media e.g. a Stack Exchange post which might have images, code formatting, text formats, etc.
You could use Django Pagedown which aims exactly to offer a way of editing similar to that found on stackexchange sites. As for now you cannot yet upload images (this feature is though on the todos list of the author), they must be already uploaded somewhere on the web and you can insert them using their url.
I am using django to create an application that read data from sql server and show it on the webpage.
I want the content to change based on selected options from the drop down.
Basically I have written queries ion the model and I want my model to load content dynamically. How can I do that?
I am trying to use ajax.
Django won't care a whole lot about what you want to do there. Essentially, you want to create controller actions in Django that serve e.g. JSON representations of the data you want to display.
Your template then needs to include Javascript which makes the AJAX calls to retrieve data from those actions and display it on the page. You can either do this manually using just Javascript or jQuery or you can use a framework like AngularJS. The latter is heavier weight but will save you some effort if this about more than just a simple page.
There are plenty of tutorials on the web for using Django with jQuery or AngularJS which you should easily find using your favourite search engine.
I have an app that allows users (admins actually) to add html to a model. Then I serve that html on some page to other users (nonadmins). I would like to allow the admins to create arbitrary html on these pages, including adding images. I don't want the admins to have to jump through hoops to get their content into this html field. Suppose a user has some images on their local machine that they want to go into this html field they are creating. I want it to be super brain-dead easy for them to get those images in there.
Right now I just have a model with an html field and I provide a WYSIWYG editor . On a page that users can see, I just load that model.html (filter it as safe) and display. But if the admin user wants to add an image, they still have to figure out hosting and linking in their html document.
Is there a way to use Django flatpages + static to achieve this? Or some kind of app that provides a wordpress-like editor inside Django?
Honestly I would recommend just installing Mezzanine. It does exactly what you want and is the most lightweight, simple and Wordpress like of the Django CMSs. It integrates TinyMCE and Django filebrowser like you want and you can throw away the bits you don't want. This is almost definitely the quickest way to do what you want.
I would like to create a single page in the admin site of django where I can change some global variables of the website (title of the website, items in the navigation menu, etc). At the moment I have them coded as context processors but I would like to make them editable. Something similar to what happens in WordPress.
Is this possible?
I can store the data in the databse, but can I have a link in the admin site that goes straight to the first document record and doesnt allow the creation of multiple records (they wouldnt make sense)
Instead of creating a model in the database, would it be possible to change some context_processor from the admin site (I think this would be best)
django-preferences does exactly what you are looking for. The implementation is a bit hacky (particularly the setting of __module__ on the model class to trick Django into thinking it was loaded from a different app), but it works.
This sounds like what the sites framework is intended to help with.
http://docs.djangoproject.com/en/stable/ref/contrib/sites/
"It’s a hook for associating objects and functionality to particular Web sites, and it’s a holding place for the domain names and “verbose” names of your Django-powered sites."
The docs make it sound like it's only good for multiple sites, but it's a great place to put stuff in a single-site-per-django model too.
There's an app called django-values that allows you storing of specific settings in the database.