I am building in Python on django framework. Having done some tutorials, I now want to build a very simple lightweight application.
The first part of my application is that I need a user system. i.e. a way for people to sign up and a way for me to keep their information private.
What is the easiest way for me to set this up?
Any pre-existing code you could point me to? Or any tutorials that you particularly think are good?
django-registration should get you started.
Related
In a school project, my team and I have to create a shopping website with a very specific server-side architecture. We agreed to use python and turned ourselves towards Django since it seemed to offer more functionalities than other possible frameworks. Be aware that none of us ever used Django in the past. We aren't masters at deploying application on the web either (we are all learning).
Here's my problem: two weeks in the project, our teacher told us that we were not allowed to use any ORM. To me, this meant bye bye to Django models and that we have to create everything on our own.
Here are my questions: as we already have created all our python classes, is there any way for us to use them alongside our Django app? I have not seen any example online of people using their own python classes within a Django app. If it were possible, where should we instantiate all our objects? Would it be easier to just go with another framework (I am thinking about Flask). Am I just missing important information about how Django works and asking a dumb question?
We have 4 weeks completed and 6 more to go before finishing our project. I often see online "use Flask before using Django" since it is simpler to use. We decided on Django because in the project description, Django was recommended but not Flask.
Thanks for the help.
Without being an absolute Django expert, here is my opinion.
The Django ORM is far from being the only feature this Framework has to offer (URLs routing, test client, user sessions variables, etc.), but surely it is one the main component you want to use while working with Django since it is often directly linked to other core features of Django.
If using the ORM is completely forbidden, a lot of features out of the box won't be available for you. One of the main features I can think about is the admin interface. You won't be able to use it if the ORM is not an option for you.
So, in my opinion, you should go for another Framework like Flask. Mainly because without using the ORM, some of the Django value is gone.
Hope it helps!
I'm building a webapp and needed to choose between Django and Pyramid. I decided to go with Pyramid.
I understand Pyramid comes with its own authentication/authorization framework which looks nice. But I haven't seen anywhere in Pyramid where users/groups/permissions are defined. In Django these things come for free.
I'm using SQLAlchemy and was wondering if there are similar users/groups/permissions already built that I can import. I'd rather not define these objects/mappings and hash/salting of passwords myself.
Django's definitions of these things are pretty much all I need.
Can anyone point my to something I can use? Or do I need to roll my own?
Pyramid has a much more flexible authentication system. And yes, if you want something simple like Django's user/group/permission concept, then flexible might be scary.
Pyramid does not have a "User" object, as it makes no assumptions about how you store your data or what ORM you use, therefore there isn't something for you like contrib.auth. You will need to hash/salt the passwords yourself using a library such as cryptacular or passlib, both found on PYPI.
As far as wanting user/group/permissions within Pyramid's system, this is achievable pretty simply by defining a RootFactory that has an __acl__ that maps groups to permissions. Permissions are assigned to views, thus are pretty static usually. If you'd like the groups (what Pyramid calls "principals") to be dynamic that is also achievable.
I'd suggest looking at the Pyramid wiki2 tutorial, as well as the shootout demo.
There are also a couple third-party packages for assisting with authorization within Pyramid if you plan to be using SQLAlchemy. apex is a more full stack solution, and ziggurat_foundations is a lower-level layer above SQLAlchemy to help you set up users and groups for your application.
Your question is fairly high level and authorization is a "hard problem", so I'll stop here and avoid regurgitating the tutorials and resources that already exist from the Pyramid tutorials to several third-party examples. If you have any specific questions please feel free to ask those in another question.
I'm looking at building a website using Web.py, and there is no built-in authentication system. Having read various things about authentication on websites, a common theme I keep hearing is "Don't roll your own, use someone else's." There are some examples of simple authentication on the site, like this one, but they all say at the bottom "Don't use this in production code."
So then, is there a generic authentication library for Python that I could use with Web.py? Or, is it really not that hard to roll my own?
If you can't find one easily, then probably discarding the advice and rolling your own is not a bad choice.
I don't think you'll find anything out of the box. The authentication system, is coupled with and dependent on the architecture (in your case probably it is Web only). Having said that it'll perhaps be easier to integrate django's authentication (django.contrib.auth) by putting some hooks here and there with web.py. Even then, it'll import a lot of django'ish ORM and other stuff behind the scene, but it is definitely possible.
Try repoze.who / what - it's implemented as WSGI middleware, so should fit into your stack well.
I'm looking at django-registration. It's in alpha 0.8, and hasn't been updated for 12/13 months. But it seems this is what most people use? I'm just wondering if there is a production standard package out there for managing users on a django site, or do people tend to roll their own?
It hasn't been updated because it works very well ;)
Frankly, you really should use this package, along with django-profiles, django-invitation...
The only problem (for me) is the lack of example templates in django-registration
But you can look at this repository to get some
Try django-registration-redux, a maintained fork of django-registration:
https://github.com/macropin/django-registration
https://django-registration-redux.readthedocs.org/en/latest/
I am working on a GAE app that is going to use its own registration module. It works using AJAX, can create new users in database, send codes for verifying new users and recovering existing users by email. I am almost done with this module and I am sure it won't take much time to configured for using with Django models for works with database. The important thing you could take from there is the concept of the registration/verification/restoring processes. Please feel free to clone the module from here and participate in developing it. You can also ping me if you have any questions, I will help with pleasure! Thanks.
I've been learning python for use in ArcGIS and some other non-web applications. However, now that I've taken on building a personal website I am interested in using it for web development (as it is the only scripting language I currently know).
I've noticed that there are a lot of these things called "frameworks", such as Django. From what I understand they are just a collection of packages to save you from re-inventing the wheel but I don't really know how they work.
Furthermore, I do not like GUIs, if I need a framework I would like to find one that could be used through a terminal, starts out simple and can be scaled for more complexity when I'm ready. Any advice or ideas on frameworks and why I would want to use one?
The Python web frameworks have nothing to do with GUIs, and can all be used via the terminal.
The benefits of a framework, as you say, are all to do with making your life easier by supplying the components you need to build a website: the main ones are database interaction through an ORM, a templating system, and URL routing. On top of that, the big frameworks also included optional extras like user authentication, administration interface, and so on.
Personally I like Django, but your mileage may vary: I would say, though, that whatever you do with Python and the web will require some sort of framework, even if it's one of the absolute minimal ones like Flask which basically do just the routing part. There's simply no point in writing all this stuff from scratch when it's been done for you.
I'd second the post above: Django is a great framework and will save you loads of time in the long run.
Pretty much every challenge you'll come across when writing a web application will already have been solved, e.g. How do I send emails? What about an admin interface to edit the data? User security?
In my view picking the best framework is all about the ecosystem around that framework. How well used is it? Is it discussed widely on the internet? Have others encountered, and solved, the problems I'm facing?
In terms of where you start, see the Django Tutorial here:
http://docs.djangoproject.com/en/1.2/intro/tutorial01/
If you think Django offers you too much, I'd recommend that you take a look at CherryPy just to compare the different, and much simpler, approach.
With Python, you've got lots of options. To start, I would recommend looking here -- it explains the basics and provides a fairly complete list of frameworks.
If you're looking for something that starts out simple but can also handle more complexity, then you should take a look at web2py. It requires no installation or configuration, has no dependencies, and includes a web server and a relational database. It also includes an optional web-based integrated development environment and admin interface, but you can work through the terminal instead if you prefer.
It's very easy to learn and was designed for ease of use, faster development, and security. You can get a lot done with very little code thanks to the included scaffolding app along with many sensible default behaviors. As things get more complex, web2py can handle it, as it is a well-integrated full-stack framework with lots of built-in functionality, including a database abstraction layer, form handling and validation, access control, web services, and easy Ajax integration.
Personnally, I don't use any framework, I write either from scratch on BaseHTTPServer, or using WSGI (with mod_wsgi).
It is a bit long to write the skeleton, but I think it is faster (I mean at runtime), there is less constraints, and there is lesser to learn.