Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.
I've just been getting into Django and I really really like it. Here's the long-winded rant/odyssey about how I finally found a way to develop web-apps that finally seems makes sense to me:

I've been using PHP for the past five years and have always hated it. As Larry Wall once said, PHP really does bring "worse is better" to new levels. Though I appreciate PHP's practicality for small scripts, it's universal support, and how it was responsible for making the development of dynamic websites accessible to mere mortals, it really is just a horrible awful programming language.

For the past few years I've been trying to find a viable Perl alternative. I know Perl pretty darn well and it just seems every time every time I try to get something like Catalyst, Embperl, or Mason working, it just turns into a nightmare. The CPAN installs always fail, nothing can "just work" from the beginning, and I'm forced to try and figure out if I want Apache::Session, Embperl::Session, Apache::SessionX, and then it forces me to decide where to store the data for my sessions, and oh wait, CentOS 3 or 4? has mod_perl 1.99.FAIL which will make everything blow up no matter what you do, and they refuse to issue a working alternative RPM. Can't Perl just work??? It's a fun, expressive language, and I don't know if these problems arise from the "there is more than one way to do it" philosophy, or the fact that the "all-star" Perl developers are all focused on bulking up Perl 6's vaporware.

I also tried to just develop simple applications with mod_perl. Mod_perl is pretty clean and simple these days (since the 1.0 -> 2.0 insanity) and has really good support across distros and cpanel. I wrote some Apache handlers with mod_perl and I thought it was totally awesome how lightning fast they were, especially with database access. The only problem is that in order to write a web app on mod_perl alone, I'd really be on my own. I'd have to pick and choose my CPAN modules and hope that people are using them in the future, and "roll my own" of so many things, that it just didn't seem practical for rapid web application development.

So I ran back to PHP and cried a lot. About a month or so ago I decided to try Ruby out. I had seen their screencasts, and a post-grad friend of mine always raves about Ruby's OOP purity, so I figured I'd give Ruby and Rails a chance.

I learned a bit of Ruby, and it's definitely not as mature as Python and Perl in terms of having a large collection of libraries for doing various things. I downloaded the MySQL extension and started goofing around and had some fun. The language didn't feel as responsive on the command line like Python and Perl, but that's no problem.

Then I started trying to learn Rails. At this point the latest version is 2.x and I just couldn't seem to find ANY decent up-to-date learning material aside from the reference manual. The tutorials and screencasts I did find, left me with a simple webapp that worked, but without any understanding of how all the RoR's black magick involved in created that app (like scaffolding) works. One major tutorial (I think it was the official one) had blatently wrong errors that I had to work around. In the end I just felt like I spent two days watching a bunch of guys "show off". After doing a little more research on the poor status of rails documentation, the general consensus of the blogging community seems that the Rails people are more interested in getting you to buy the book.

I also didn't like that the current recommended strategy for production use of rails is to Proxy requests through Apache to a bunch of mongrel processes. In order to do this, you need a bleeding edge version of Apache which just isn't practical if you want to deploy on an existing server. I managed to setup a mongrel cluster on my home computer (4-core 2.6ghz core 2 CPU) and if I recall correctly I got about 1000 requests per second on a hello world app. This isn't terrible, about the same speed as a hello world PHP app, but I could get django to go much much faster.

I also didn't like Ruby so much as a language. I think it's amazing that it's essentially a pure OOP language like SmallTalk, only with modern syntax (even though its purity might make the language a little less practical in terms of speed) I was also happy to find built-in support for Perl's regular expressions; however, I feel Ruby took a bit too much of the ugliness of Perl with it. (Matz even admits this) Another really really big problem with Ruby is that it doesn't support [a=http://spec.ruby-doc.org/wiki/Ruby_Threading]"real" threads[/url]. This was a really bad design choice considering the way CPUs are being built these days, and that flaw alone, is reason enough to not take Ruby as a "serious" language for general purpose for business use. (Yes this will probably be fixed with other VMs or implementations in the future)

So after failing miserably in learning Ruby on Rails, I found out about Django. I went through the getting started tutorial, and as soon as I read that the preferred production setup was PostgreSQL with Apache/mod_python, I instantly knew these guys were serious about developing a practical, scalable framework. As I started learning how to do things, I was amazed that, it seemed like the first time ever, that things were actually making sense!. Probably what I love the most is that the Django people take an amazing approach to documentation: instead of showing off all these neat magical features, they start by showing you the "dumb" way to do something so you can understand what's happening from top to bottom, then they gradually show you all the shortcuts and design patterns Django offers to make life easier. And best of all, Django is FAST! On one of my xeon servers, I could get a hello world app in Django to perform pretty much on-par with a mod_perl apache module. Not only was the framework simple, it was lightweight.

So I'm very excited about Django, but I won't know for sure if it's the as good as I hope it will be until I actually write a full web application with it. So in closing, I'd just like to say that I sincerely thank those of you (especially ATLbeer) who are putting their time and effort into making Django better and more mainstream.

Adbot
ADBOT LOVES YOU

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

jarito posted:

I also tried 'request.POST.has_key('books_isbn') with the same results. Am I going about this the wrong way? Is there a more accepted way to do what I am trying to do?
Your if statement logic should be reversed. Change:
code:
def add(request):
    if request.POST.__contains__('books_isbn'):
        return render_to_response('books/books_add.html')
    else:
        return render_to_response('books/books_add.html', {
                  'book': lookup_book(request.POST['book_isbn']),})
to:
code:
def add(request):
    if 'books_isbn' not in request.POST:
        return render_to_response('books/books_add.html')
    else:
        return render_to_response('books/books_add.html', {
                  'book': lookup_book(request.POST['book_isbn']),})
The problem is when the code "request.POST['book_isbn']" gets called. If the value doesn't exist, an exception is raised.

May I also suggest you put the ISBN in the URL? ISBNs are only numbers and hyphens so it should look fine, and allow people to copy and paste the URL. Example: http://mysite.com/book/isbn/978-3-16-148410-0/

jarito posted:

Also as a side note, what is the standard tab=space settings for python code?
I believe the vast majority of people use 4-space tabs. I strongly recommend against using tabs with Python because each editor seems to do its own wacky thing when in "tabs mode" and your source can easily get unaligned, if not interpreted incorrectly by Python.

The Real Ambassador fucked around with this message at 07:13 on Apr 15, 2008

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

duck monster posted:

PHP's syntax is sort of like javas. But honetstly, PHP's actual language isn't in the ballpark. Python does real OO, and does it loving well (Granted php5 is starting to look a bit more like real oo) and for added fun, you can still hang out in java land using Jython (or c# land using ironpython) and it all works smooth as poo poo. Hell, Java's Groovy is a pretty much self confessed rip of python but java-ish.
I agree, Python feels a lot like Java in many way. They both share a similar packaging system, strong OOP features, and the "There Is Only One Way To Do It" philosophy. What I like about Python is it "fits in" better with the *nix world, doesn't take 3 seconds to load the VM, is simpler, and in my opinion, more practical for general development.

It really irritates me when people think languages are similar because they both have curly brackets.

The Real Ambassador fucked around with this message at 09:04 on Apr 15, 2008

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

Space Kimchi posted:

Yeah this. But the idea behind Django's media server stuff is that apache/(*snicker*)IIS/whatever are much faster at serving up files than the Django framework is. Why load up the entire goddamned python engine just to serve a static file? As such, the css, etc. is supposed to be given its own subdomain or otherwise served up straight from the web server, which is better and faster at serving static files.
Also there are companies out there that will host your static files.

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

Space Kimchi posted:

You mean like the one you're paying to run your Django application on? :confused:
Lots of people like to host their static content on different servers. For example you could use a content distribution network like Akamai. These are networks that can host your files in geographically disperse areas so the number of hops between your visitor and static content (which is like 80% of the bandwidth) is much lower. It also helps take load off your server.

You might also want to just setup another dedicated server for static content running like nginx instead of apache.

In these situations it's helpful to be able to configure MEDIA_URL.

Edit: beaten :(

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

deimos posted:

:woop:

FINALLY got django working with MS SQL Server from a CentOS host.
I dare you to get blob fields to work.

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

Space Kimchi posted:

When 1.0 rolls out, is it likely that if I upgrade my existing applications will work just fine (none of them use any particularly fancy or hackish features) or will there likely be some problems to crop up?

Trunk has broken my projects at least 6 times in the past couple months as they've been trying to clean up the codebase.

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

mwarkentin posted:

Thought I'd bump this for RC1! http://www.djangoproject.com/weblog/2008/sep/02/10-rc1/

Also, I've got a question regarding payment gateways.. I need to integrate one into a project I'm working on.. are there any out there that I can just plug in?

What's the easiest to integrate with? Paypal? Authorize.net?

Pros & cons?

I use: http://pypi.python.org/pypi/zc.authorizedotnet/1.3

I had to write a hack to be able to do AUTH_CAPTURE transactions though:

code:
from zc.authorizedotnet.processing import CcProcessor

class MyCcProcessor(CcProcessor):
    def authorizeAndCapture(self, **kws):
        if not isinstance(kws['amount'], basestring):
            raise ValueError('amount must be a string')
        return self.connection.sendTransaction(type='AUTH_CAPTURE', **kws)

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

bitprophet posted:

code:
                prepopulate_from("title",),
Please explain what this line is doing, and why it differs from the others around it, and hopefully that will clue you in on what's wrong :)

That's a magical feature from 0.96 that will automatically fill in your field based on what is entered into the title field. I believe they took that out of 1.0 so please steer away from it.

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

bitprophet posted:

This is true, but not what I was getting at, he has a pretty silly syntax error :)

Forgive me, I didn't know your code had a gender.

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

FrontLine posted:

Can anybody help me out with creating an Object outside of the Django Admin console and the Python shell. I'd like to be able to run a script like this:

'createobject.py'
code:
from News.models import ChoiceArticle as CA
NewCA = CA()
NewCA.Title = "News Story title"
NewCA.URL = "http://www.genericnewssite.com"
NCA.Summary = "A summary of what the story is about"
NCA.save()
But, as possibly expected, I keep getting an ImportError:

code:
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
Any idea how to get around this?

Put this in your codes at the top:

import sys
import os
sys.path.append('..')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

MEAT TREAT posted:

My question has more to do with the hosting of this project. I'm expecting it to generate a lot of traffic and wanted to know if those shared hosting plans would be enough. At what point will 64 MB not be enough to serve all my users? I don't have a lot of money right now, so I wanted to see how long that shared hosting would last me.

Why not just use shared hosting until it becomes apparent that it is no longer enough? Shared hosting can host more than you'd think. By the time your website becomes so popular that you need a dedicated server, chances are you'll be making enough off ads to cover a good portion of the cost.

To put off the need for a dedicated server, you can even be clever and get several shared hosting accounts with different companies. For example, one could host your static content, the other could be for your Django code. That might help reduce the possibility of your hosting company murdering you for using too much of their "unlimited" resources. It happens, but not as much as it used to. Back in 2000, I had a popular little webpage that got a bunch of visitors. The next thing I knew my credit card was getting hit with $300 charges for excessive bandwidth usage on my Unlimited* account. I guess the moral of the story is to be wary of any host that offers "unlimited*" resources.

The Real Ambassador fucked around with this message at 09:07 on Sep 8, 2008

Adbot
ADBOT LOVES YOU

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

the talent deficit posted:

I just spent three hours hacking django to remove autoescaping only to learn there's a 'safe' filter tag that prevents autoescaping. :(

Aww I'm sorry. One time I searched for three hours to figure out how to escape template tags like this: {% hello %} Sometimes you come across features that are just so hard to search for.

I personally couldn't live without auto-escaping. I think it's one of the best features they could have possibly implemented into Django.

Also what is up with the new documentation layout? It's harder to navigate and they couldn't even create 301 redirects from the old URLs. Tsk tsk...

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply